﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using HML.Design;

namespace HML
{
    /// <summary>
    /// 下拉列表控件
    /// </summary>
    [Description("下拉列表控件")]
    [DefaultProperty("Multiple")]
    [DefaultEvent("SelectedItemsChanged")]
    [TypeConverter(typeof(PropertyOrderConverter))]
    [Designer(typeof(DropDownListPlusDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(DropDownListPlus), "Controls.DropDownListPlus.Resources.DropDownListPlus.bmp")]
    public class DropDownListPlus : DpiControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(DropDownListPlus)).GetName().Name, typeof(DropDownListPlus).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled= SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);

                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        void ISkinObject.InitializeInvalidate()
        {
            this.InitializeElement();
            this.Invalidate();
        }

        void ISkinObject.Invalidate()
        {
            this.Invalidate();
        }

        #endregion

        #region 新增事件

        private static readonly object EventItemsSourceChanged = new object();
        /// <summary>
        /// 数据源更改事件
        /// </summary>
        [Description("数据源更改事件")]
        public event EventHandler ItemsSourceChanged
        {
            add { Events.AddHandler(EventItemsSourceChanged, value); }
            remove { Events.RemoveHandler(EventItemsSourceChanged, value); }
        }

        private static readonly object EventSelectedItemsChanged = new object();
        /// <summary>
        /// 选项选中更改事件
        /// </summary>
        [Description("选项选中更改事件")]
        public event EventHandler SelectedItemsChanged
        {
            add { Events.AddHandler(EventSelectedItemsChanged, value); }
            remove { Events.RemoveHandler(EventSelectedItemsChanged, value); }
        }

        public delegate void DropDownListPlusDrawItemBeforeEventHandler(object sender, DropDownListPlusItemDrawBeforeEventArgs e);
        private static readonly object EventItemDrawBefore = new object();
        /// <summary>
        /// 选项自定义绘制前事件
        /// </summary>
        [Description("选项自定义绘制前事件")]
        public event DropDownListPlusDrawItemBeforeEventHandler ItemDrawBefore
        {
            add { Events.AddHandler(EventItemDrawBefore, value); }
            remove { Events.RemoveHandler(EventItemDrawBefore, value); }
        }

        public delegate void DropDownListPlusDrawItemAfterEventHandler(object sender, DropDownListPlusItemDrawAfterEventArgs e);
        private static readonly object EventItemDrawAfter = new object();
        /// <summary>
        /// 选项自定义绘制后事件
        /// </summary>
        [Description("选项自定义绘制后事件")]
        public event DropDownListPlusDrawItemAfterEventHandler ItemDrawAfter
        {
            add { Events.AddHandler(EventItemDrawAfter, value); }
            remove { Events.RemoveHandler(EventItemDrawAfter, value); }
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler PaddingChanged
        {
            add { base.PaddingChanged += value; }
            remove { base.PaddingChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ImeModeChanged
        {
            add { base.ImeModeChanged += value; }
            remove { base.ImeModeChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageChanged
        {
            add { base.BackgroundImageChanged += value; }
            remove { base.BackgroundImageChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageLayoutChanged
        {
            add { base.BackgroundImageLayoutChanged += value; }
            remove { base.BackgroundImageLayoutChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TextChanged
        {
            add { base.TextChanged += value; }
            remove { base.TextChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackColorChanged
        {
            add { base.BackColorChanged += value; }
            remove { base.BackColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ForeColorChanged
        {
            add { base.ForeColorChanged += value; }
            remove { base.ForeColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click
        {
            add { base.Click += value; }
            remove { base.Click -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DoubleClick
        {
            add { base.DoubleClick += value; }
            remove { base.DoubleClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseClick
        {
            add { base.MouseClick += value; }
            remove { base.MouseClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseDoubleClick
        {
            add { base.MouseDoubleClick += value; }
            remove { base.MouseDoubleClick -= value; }
        }

        #endregion

        #region 新增属性

        private bool roundEnabled = true;
        /// <summary>
        /// 是否启用圆角
        /// </summary>
        [Description("是否启用圆角")]
        [Category("杂项")]
        [PropertyOrder(-196)]
        [DefaultValue(true)]
        public bool RoundEnabled
        {
            get { return this.roundEnabled; }
            set
            {
                if (this.roundEnabled == value)
                    return;

                this.roundEnabled = value;
                this.SetControlShape();
                this.Invalidate();
            }
        }

        private DropDownListPlusItemCollection itemsSourceCollection;
        /// <summary>
        /// 选项集合
        /// </summary>
        [PropertyOrder(-184)]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public DropDownListPlusItemCollection ItemsSource
        {
            get
            {
                if (this.itemsSourceCollection == null)
                {
                    DropDownListPlusItemCollection tmp = new DropDownListPlusItemCollection();
                    tmp.SetOwner(this);
                    this.itemsSourceCollection = tmp;
                }
                return this.itemsSourceCollection;
            }
        }

        private ContentObject content;
        /// <summary>
        /// 选项区域风格
        /// </summary>
        [Description("选项区域风格")]
        [Category("杂项")]
        [PropertyOrder(-183)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ContentObject Content
        {
            get
            {
                if (this.content == null)
                    this.content = new ContentObject(this);
                return this.content;
            }
        }

        private bool clearButtonVisible = false;
        /// <summary>
        /// 是否显示清除按钮
        /// </summary>
        [Description("是否显示清除按钮")]
        [Category("杂项")]
        [PropertyOrder(-182)]
        [DefaultValue(false)]
        public bool ClearButtonVisible
        {
            get { return this.clearButtonVisible; }
            set
            {
                if (this.clearButtonVisible == value)
                    return;

                this.clearButtonVisible = value;
                this.InitializeElement();
                this.Invalidate();
            }
        }

        private DropDownButtonObject dropDownButton;
        /// <summary>
        /// 下拉按钮
        /// </summary>
        [Description("清除按钮")]
        [Category("杂项")]
        [PropertyOrder(-180)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DropDownButtonObject DropDownButton
        {
            get
            {
                if (this.dropDownButton == null)
                    this.dropDownButton = new DropDownButtonObject(this);
                return this.dropDownButton;
            }
        }

        private PickerObject picker;
        /// <summary>
        /// 下拉面板
        /// </summary>
        [Description("下拉面板")]
        [Category("杂项")]
        [PropertyOrder(-176)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public PickerObject Picker
        {
            get
            {
                if (this.picker == null)
                    this.picker = new PickerObject(this);
                return this.picker;
            }
        }

        private bool readOnly = false;
        /// <summary>
        /// 是否只读
        /// </summary>
        [Description("是否只读")]
        [Category("杂项")]
        [PropertyOrder(-175)]
        [DefaultValue(false)]
        public bool ReadOnly
        {
            get { return this.readOnly; }
            set
            {
                if (this.readOnly == value)
                    return;

                this.readOnly = value;
                if (value)
                {
                    this.activatedIndex = -1;
                    if (this.nativeWindow != null)
                    {
                        this.nativeWindow.Hide();
                    }
                    if (this.Focused)
                    {
                        IContainerControl c = this.Parent.GetContainerControl();
                        if (c != null)
                        {
                            ((Control)c).SelectNextControl(this, true, true, true, true);
                        }
                    }
                }

                this.Height += 1;
                this.Invalidate();
            }
        }

        private bool multiple = false;
        /// <summary>
        /// 是否允许多个选中
        /// </summary>
        [Description("是否允许多个选中")]
        [Category("杂项")]
        [PropertyOrder(-174)]
        [DefaultValue(false)]
        public bool Multiple
        {
            get { return this.multiple; }
            set
            {
                if (this.multiple == value)
                    return;

                this.multiple = value;
                if (this.nativeWindow != null)
                {
                    this.nativeWindow.Hide();
                }
                if (!this.multiple && this.selectedItems.Count > 1)
                {
                    this.selectedItems = new List<DropDownListPlusItem> { this.selectedItems[0] };
                    this.InitializeElement();
                    this.Invalidate();

                    this.OnSelectedItemsChanged(EventArgs.Empty);
                }
                else
                {
                    this.InitializeElement();
                    this.Invalidate();
                }
            }
        }


        private ArrayList selectedItemsInfo = new ArrayList();
        private List<DropDownListPlusItem> selectedItems = new List<DropDownListPlusItem>();
        /// <summary>
        /// 已选中选项集合 (多选模式)
        /// </summary>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public List<DropDownListPlusItem> SelectedItems
        {
            get { return this.selectedItems; }
            set
            {
                if (value == null)
                    value = new List<DropDownListPlusItem>();

                List<DropDownListPlusItem> itemArr = new List<DropDownListPlusItem>();
                for (int i = 0; i < value.Count; i++)
                {
                    int index = this.ItemsSource.IndexOf(value[i]);
                    if (index == -1)
                    {
                        throw new ArgumentNullException("value不属于该集合");
                    }

                    DropDownListPlusItem item = this.ItemsSource[index];
                    if (itemArr.IndexOf(item) == -1)
                    {
                        itemArr.Add(item);
                    }
                }

                if (!this.IsEqualList(this.selectedItems, itemArr))
                {
                    this.selectedItems = itemArr;
                    this.InitializeElement();
                    this.Invalidate();

                    this.OnSelectedItemsChanged(EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// 已选中选项 (单选模式)
        /// </summary>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public DropDownListPlusItem SelectedItem
        {
            get
            {
                if (this.selectedItems.Count == 0)
                    return null;

                return (this.selectedItems[0]);
            }
            set
            {
                List<DropDownListPlusItem> itemArr = new List<DropDownListPlusItem>();
                if (value != null)
                {
                    itemArr.Add(value);
                }

                this.SelectedItems = itemArr;
            }
        }

        /// <summary>
        /// 清楚按钮鼠标是否已进入
        /// </summary>
        [Browsable(false)]
        public bool ClearButtonIsMouseEnter
        {
            get { return this.mouseenterobject == this.clearbutton_object; }
        }

        /// <summary>
        /// 下拉按钮鼠标是否已进入
        /// </summary>
        [Browsable(false)]
        public bool DropDownButtonIsMouseEnter
        {
            get { return this.mouseenterobject == dropdrowbutton_object; }
        }

        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(120, 29); }
        }

        public override Font Font
        {
            get { return base.Font; }
            set
            {
                base.Font = value;
                this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, this.Height, BoundsSpecified.Size);
            }
        }

        protected override ImeMode DefaultImeMode
        {
            get { return ImeMode.Disable; }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
            set { base.ImeMode = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string Text
        {
            get { return base.Text; }
            set { base.Text = value; }

        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Image BackgroundImage
        {
            get { return base.BackgroundImage; }
            set { base.BackgroundImage = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set { base.BackgroundImageLayout = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.Normal.BackColor ; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.Content.Item.Normal.TextColor; }
            set { }
        }

        #endregion

        #region 字段

        /// <summary>
        /// 控件激活显示状态（配合Focused 、ShowFocusCues、activatedIndex使用）
        /// </summary>
        private bool activatedState = false;
        /// <summary>
        /// 控件激活状态选项索引（-1 没有、0 下拉按钮、1 清除按钮 ）
        /// </summary>
        private int activatedIndex = -1;

        /// <summary>
        /// 当前鼠标已按下的对象
        /// </summary>
        private object mousedownobject = null;
        /// <summary>
        /// 鼠标进入对象
        /// </summary>
        private object mouseenterobject = null;
        /// <summary>
        /// 清空按钮对象
        /// </summary>
        private object clearbutton_object = new object();
        /// <summary>
        /// 下拉按钮对象
        /// </summary>
        private object dropdrowbutton_object = new object();

        /// <summary>
        /// 内容区域rect（排除上下边框、内边距 。但包含左右边框、内边距）
        /// </summary>
        private Rectangle content_rect = Rectangle.Empty;
        /// <summary>
        /// 清空按钮rect
        /// </summary>
        private Rectangle clearbutton_rect = Rectangle.Empty;
        /// <summary>
        /// 下拉按钮rect
        /// </summary>
        private Rectangle dropdrowbutton_rect = Rectangle.Empty;

        /// <summary>
        /// 下拉列表弹层
        /// </summary>
        private DropDownListPlusNativeWindow nativeWindow = null;
        /// <summary>
        /// 是否处于点击控件自身来关闭下拉列表弹层状态
        /// </summary>
        private bool isControlSelfClosing = false;

        /// <summary>
        /// 边框
        /// </summary>
        private int borderThicknes = 1;

        #endregion

        public DropDownListPlus()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.StandardClick, false);//自定义单击事件逻辑
            SetStyle(ControlStyles.StandardDoubleClick, false);//停用双加事件

            this.InitializeElement();
            this.OnSkinChanged();
        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.InitializeElement();
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            Color border_color = this.Enabled ? this.StyleAppearance.Normal.BorderColor : this.StyleAppearance.Disabled.BorderColor;
            Color content_color = this.Enabled ? this.StyleAppearance.Normal.BackColor : this.StyleAppearance.Disabled.BackColor;

            //背景
            {
                SolidBrush back_sb = new SolidBrush(content_color);
                g.FillRectangle(back_sb, this.ClientRectangle);
                back_sb.Dispose();
            }

            g.SetClip(this.content_rect);

            // 选中选项
            if (this.selectedItems.Count > 0)
            {
                if (this.Multiple)
                {
                    Pen item_border_pen = new Pen(this.Enabled ? this.StyleAppearance.Content.Item.Normal.BorderColor : this.StyleAppearance.Content.Item.Disabled.BorderColor);
                    SolidBrush item_back_sb = new SolidBrush(this.Enabled ? this.StyleAppearance.Content.Item.Normal.BackColor : this.StyleAppearance.Content.Item.Disabled.BackColor);
                    SolidBrush item_text_sb = new SolidBrush(this.Enabled ? this.StyleAppearance.Content.Item.Normal.TextColor : this.StyleAppearance.Content.Item.Disabled.TextColor);
                    SolidBrush item_clearbutton_back_sb = new SolidBrush(this.Enabled ? this.StyleAppearance.Content.Item.Normal.ClearButtonBackColor : this.StyleAppearance.Content.Item.Disabled.ClearButtonBackColor);
                    Pen item_clearbutton_fore_pen = new Pen(this.Enabled ? this.StyleAppearance.Content.Item.Normal.ClearButtonForeColor : this.StyleAppearance.Content.Item.Disabled.ClearButtonForeColor);

                    for (int i = 0; i < this.selectedItemsInfo.Count; i++)
                    {
                        DropDownListPlusItemInfo iteminfo = (DropDownListPlusItemInfo)this.selectedItemsInfo[i];

                        //背景
                        g.FillRectangle(item_back_sb, iteminfo.item_rect);

                        // 选项图片
                        Image commom_image = null;
                        if (this.Picker.Item.Icon.Visible)
                        {
                            commom_image = (iteminfo.item.Image == null) ? this.Picker.Item.Icon.Image : iteminfo.item.Image;
                        }
                        if (commom_image != null)
                        {
                            g.DrawImage(commom_image, iteminfo.item_image_rect);
                        }

                        //文本
                        g.DrawString(iteminfo.item.Text, this.Font, item_text_sb, iteminfo.item_text_rect, StringFormat.GenericTypographic);

                        //删除按钮
                        if ((this.Content.Item.ClearButtonVisible && !this.ReadOnly))
                        {
                            float item_clearbutton_ico_radius = iteminfo.item_clearbutton_rect.Width / 2 * 2 / 3;
                            PointF item_clearbutton_ico_center = new PointF(iteminfo.item_clearbutton_rect.X + iteminfo.item_clearbutton_rect.Width / 2, iteminfo.item_clearbutton_rect.Y + iteminfo.item_clearbutton_rect.Height / 2);
                            PointF[] item_clearbutton_ico_lineArr = new PointF[] { ControlHelper.CalculatePointForAngle(item_clearbutton_ico_center, item_clearbutton_ico_radius, 225), ControlHelper.CalculatePointForAngle(item_clearbutton_ico_center, item_clearbutton_ico_radius, 45), ControlHelper.CalculatePointForAngle(item_clearbutton_ico_center, item_clearbutton_ico_radius, 135), ControlHelper.CalculatePointForAngle(item_clearbutton_ico_center, item_clearbutton_ico_radius, 315) };
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                            g.FillEllipse(item_clearbutton_back_sb, new Rectangle(iteminfo.item_clearbutton_rect.X + 1, iteminfo.item_clearbutton_rect.Y + 1, iteminfo.item_clearbutton_rect.Width - 2, iteminfo.item_clearbutton_rect.Height - 2));
                            g.DrawLine(item_clearbutton_fore_pen, item_clearbutton_ico_lineArr[0], item_clearbutton_ico_lineArr[1]);
                            g.DrawLine(item_clearbutton_fore_pen, item_clearbutton_ico_lineArr[2], item_clearbutton_ico_lineArr[3]);
                            g.SmoothingMode = SmoothingMode.Default;
                        }

                        g.DrawRectangle(item_border_pen, new Rectangle(iteminfo.item_rect.X, iteminfo.item_rect.Y, iteminfo.item_rect.Width - 1, iteminfo.item_rect.Height - 1));
                    }

                    item_border_pen.Dispose();
                    item_back_sb.Dispose();
                    item_text_sb.Dispose();
                    item_clearbutton_back_sb.Dispose();
                    item_clearbutton_fore_pen.Dispose();
                }
                else
                {
                    DropDownListPlusItemInfo iteminfo = (DropDownListPlusItemInfo)this.selectedItemsInfo[0];

                    // 选项图片
                    Image commom_image = null;
                    if (this.Picker.Item.Icon.Visible)
                    {
                        commom_image = (iteminfo.item.Image == null) ? this.Picker.Item.Icon.Image : iteminfo.item.Image;
                    }
                    if (commom_image != null)
                    {
                        g.DrawImage(commom_image, new Rectangle(this.content_rect.X + this.borderThicknes + font_metrics.GetFontStereotypesMargim(), this.content_rect.Y + (this.content_rect.Height - font_metrics.GetFontRealHeight()) / 2, font_metrics.GetFontRealHeight(), font_metrics.GetFontRealHeight()));
                    }
                    //文本
                    SolidBrush item_text_sb = new SolidBrush(this.Enabled ? this.StyleAppearance.Content.Item.Normal.TextColor : this.StyleAppearance.Content.Item.Disabled.TextColor);
                    g.DrawString(iteminfo.item.Text, this.Font, item_text_sb, new Point(!this.Picker.Item.Icon.Visible ? (this.content_rect.X + this.borderThicknes + font_metrics.GetFontStereotypesMargim() * 2) : (this.content_rect.X + this.borderThicknes + font_metrics.GetFontStereotypesHeight()), this.ClientRectangle.Y + (this.ClientRectangle.Height - font_metrics.GetFontRealHeight()) / 2), StringFormat.GenericTypographic);
                    item_text_sb.Dispose();
                }
            }
            else
            {
                //空值提示
                if (!String.IsNullOrWhiteSpace(this.Content.NullTipText))
                {
                    Size item_nulltext_size = new Size((int)Math.Ceiling(g.MeasureString(this.Content.NullTipText, this.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                    SolidBrush item_nulltext_sb = new SolidBrush(this.StyleAppearance.Content.NullTipTextColor);
                    g.DrawString(this.Content.NullTipText, this.Font, item_nulltext_sb, new Point(this.content_rect.X + this.borderThicknes + font_metrics.GetFontStereotypesMargim() * 2, this.content_rect.Y + (this.content_rect.Height - item_nulltext_size.Height) / 2), StringFormat.GenericTypographic);
                    item_nulltext_sb.Dispose();
                }
            }

            g.ResetClip();

            //清空按钮
            if (this.ClearButtonVisible && !this.ReadOnly)
            {
                Color clearbutton_back_color = this.StyleAppearance.ClearButton.Normal.BackColor;
                Color clearbutton_fore_color = this.StyleAppearance.ClearButton.Normal.ForeColor;
                if (!this.Enabled)
                {
                    clearbutton_back_color = this.StyleAppearance.ClearButton.Disabled.BackColor;
                    clearbutton_fore_color = this.StyleAppearance.ClearButton.Disabled.ForeColor;
                }
                else if (this.ClearButtonIsMouseEnter)
                {
                    clearbutton_back_color = this.StyleAppearance.ClearButton.Enter.BackColor;
                    clearbutton_fore_color = this.StyleAppearance.ClearButton.Enter.ForeColor;
                }

                Rectangle clearbutton_ico_rect = new Rectangle(this.clearbutton_rect.X + (clearbutton_rect.Width - font_metrics.GetFontRealHeight()) / 2, this.clearbutton_rect.Y + (clearbutton_rect.Height - font_metrics.GetFontRealHeight()) / 2, font_metrics.GetFontRealHeight(), font_metrics.GetFontRealHeight());
                float clearbutton_ico_radius = clearbutton_ico_rect.Width / 2 * 2 / 3;
                PointF clearbutton_ico_center = new PointF(clearbutton_ico_rect.X + clearbutton_ico_rect.Width / 2, clearbutton_ico_rect.Y + clearbutton_ico_rect.Height / 2);
                PointF[] clearbutton_ico_lineArr = new PointF[] { ControlHelper.CalculatePointForAngle(clearbutton_ico_center, clearbutton_ico_radius, 225), ControlHelper.CalculatePointForAngle(clearbutton_ico_center, clearbutton_ico_radius, 45), ControlHelper.CalculatePointForAngle(clearbutton_ico_center, clearbutton_ico_radius, 135), ControlHelper.CalculatePointForAngle(clearbutton_ico_center, clearbutton_ico_radius, 315) };


                SolidBrush clearbutton_ico_back_sb = new SolidBrush(clearbutton_back_color);
                g.FillRectangle(clearbutton_ico_back_sb, this.clearbutton_rect);
                clearbutton_ico_back_sb.Dispose();

                Pen clearbutton_fore_pen = new Pen(clearbutton_fore_color, 2) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.DrawLine(clearbutton_fore_pen, clearbutton_ico_lineArr[0], clearbutton_ico_lineArr[1]);
                g.DrawLine(clearbutton_fore_pen, clearbutton_ico_lineArr[2], clearbutton_ico_lineArr[3]);
                g.SmoothingMode = SmoothingMode.Default;

                clearbutton_fore_pen.Width = 1;
                clearbutton_fore_pen.Color = Color.FromArgb(100, border_color);
                g.DrawLine(clearbutton_fore_pen, new Point(this.clearbutton_rect.X, this.clearbutton_rect.Y), new Point(this.clearbutton_rect.X, this.clearbutton_rect.Bottom));
                clearbutton_fore_pen.Dispose();
            }

            //下拉按钮
            {
                Color dropdrowbutton_back_color = Color.Empty;
                Color dropdrowbutton_fore_color = Color.Empty;
                if (!this.Enabled)
                {
                    dropdrowbutton_back_color = this.StyleAppearance.DropDownButton.Disabled.BackColor;
                    dropdrowbutton_fore_color = this.StyleAppearance.DropDownButton.Disabled.ForeColor;
                }
                else if (this.DropDownButtonIsMouseEnter)
                {
                    dropdrowbutton_back_color = this.StyleAppearance.DropDownButton.Enter.BackColor;
                    dropdrowbutton_fore_color = this.StyleAppearance.DropDownButton.Enter.ForeColor;
                }
                else
                {
                    dropdrowbutton_back_color = this.StyleAppearance.DropDownButton.Normal.BackColor;
                    dropdrowbutton_fore_color = this.StyleAppearance.DropDownButton.Normal.ForeColor;
                }

                Rectangle dropdrowbutton_ico_rect = new Rectangle(this.dropdrowbutton_rect.X + (dropdrowbutton_rect.Width - font_metrics.GetFontRealHeight()) / 2, dropdrowbutton_rect.Y + (dropdrowbutton_rect.Height - font_metrics.GetFontRealHeight()) / 2, font_metrics.GetFontRealHeight(), font_metrics.GetFontRealHeight());
                float dropdrowbutton_ico_x_avg = dropdrowbutton_ico_rect.Width / 6f;
                float dropdrowbutton_ico_y_avg = dropdrowbutton_ico_rect.Height / 6f;
                PointF[] dropdrowbutton_ico_lineArr = new PointF[] { new PointF(dropdrowbutton_ico_rect.X + dropdrowbutton_ico_x_avg, dropdrowbutton_ico_rect.Y + dropdrowbutton_ico_x_avg * 2), new PointF(dropdrowbutton_ico_rect.X + dropdrowbutton_ico_y_avg * 3, dropdrowbutton_ico_rect.Y + dropdrowbutton_ico_x_avg * 4), new PointF(dropdrowbutton_ico_rect.Right - dropdrowbutton_ico_x_avg, dropdrowbutton_ico_rect.Y + dropdrowbutton_ico_x_avg * 2) };

                SolidBrush dropdrowbutton_back_sb = new SolidBrush(dropdrowbutton_back_color);
                g.FillRectangle(dropdrowbutton_back_sb, this.dropdrowbutton_rect);
                dropdrowbutton_back_sb.Dispose();

                Pen dropdrowbutton_fore_pen = new Pen(dropdrowbutton_fore_color, dropdrowbutton_ico_x_avg * 8 / 9);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.DrawLines(dropdrowbutton_fore_pen, dropdrowbutton_ico_lineArr);
                g.SmoothingMode = SmoothingMode.Default;

                dropdrowbutton_fore_pen.Width = 1;
                dropdrowbutton_fore_pen.Color = Color.FromArgb(100, border_color);
                g.DrawLine(dropdrowbutton_fore_pen, new Point(this.dropdrowbutton_rect.X, this.dropdrowbutton_rect.Y), new Point(this.dropdrowbutton_rect.X, this.dropdrowbutton_rect.Bottom));
                dropdrowbutton_fore_pen.Dispose();
            }

            //边框
            this.DrawControlBorder(g, border_color, (this.Parent.Parent == null ? this.Parent.BackColor : content_color), content_color);


            //控件激活状态虚线框
            if (this.Focused && (this.ShowFocusCues || this.activatedState) && this.activatedIndex != -1)
            {
                int activated_borderthicknes_tmp = (this.Focused && this.ShowFocusCues && this.activatedIndex == -1) ? 0 : this.activatedIndex;
                int activated_borderthicknes = 1;
                Rectangle activated_rect = activated_borderthicknes_tmp == 0 ? this.dropdrowbutton_rect : this.clearbutton_rect;
                activated_rect = new Rectangle(activated_rect.X + 3 + activated_borderthicknes, activated_rect.Y + 3 + activated_borderthicknes, activated_rect.Width - 6 - activated_borderthicknes * 2 - activated_borderthicknes, activated_rect.Height - 6 - activated_borderthicknes * 2 - activated_borderthicknes);

                Pen activated_border_pen = new Pen(this.StyleAppearance.ActivateColor, activated_borderthicknes) { DashStyle = DashStyle.Dot, Alignment = PenAlignment.Center };
                g.DrawRectangle(activated_border_pen, activated_rect);
                activated_border_pen.Dispose();
            }

        }

        protected override void Select(bool directed, bool forward)
        {
            if (this.ReadOnly)
            {
                IContainerControl c = this.Parent.GetContainerControl();
                if (c != null)
                {
                    ((Control)c).SelectNextControl(this, true, true, true, true);
                }
                return;
            }

            base.Select(directed, forward);

            this.activatedState = true;
            this.activatedIndex = 0;
            this.Invalidate();
        }

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);

            this.mouseenterobject = null;
            this.Invalidate();
        }

        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);

            this.mousedownobject = null;
            this.activatedState = false;

            this.HideNativeWindow();
            this.Invalidate();
        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);

            if (!this.Enabled)
            {
                this.mousedownobject = null;
                this.activatedState = false;

                this.HideNativeWindow();
                this.Invalidate();
            }
        }

        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            if (!this.Visible)
            {
                this.mousedownobject = null;
                this.activatedState = false;

                this.HideNativeWindow();
                this.Invalidate();
            }
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);

            if (this.Parent == null)
            {
                this.mousedownobject = null;
                this.activatedState = false;

                this.HideNativeWindow();
                this.Invalidate();
            }
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.mouseenterobject = null;
            this.Invalidate();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!this.ReadOnly)
            {
                if (!this.Focused)
                {
                    this.Focus();
                }

                if (e.Button == MouseButtons.Left)
                {
                    object mousedownobject_tmp = null;

                    if (isControlSelfClosing)
                    {
                        this.isControlSelfClosing = false;
                    }
                    else
                    {
                        if (this.dropdrowbutton_rect.Contains(e.Location) || (this.DropDownButton.OperateFullArea && !this.Multiple && this.content_rect.Contains(e.Location)))
                        {
                            mousedownobject_tmp = this.dropdrowbutton_object;
                            this.activatedIndex = 0;
                            this.Invalidate();
                        }
                        else if (this.ClearButtonVisible && this.clearbutton_rect.Contains(e.Location))
                        {
                            mousedownobject_tmp = this.clearbutton_object;
                            this.activatedIndex = 1;
                            this.Invalidate();
                        }
                        else if (this.Multiple && this.content_rect.Contains(e.Location))
                        {
                            for (int i = 0; i < this.selectedItemsInfo.Count; i++)
                            {
                                if (((DropDownListPlusItemInfo)this.selectedItemsInfo[i]).item_clearbutton_rect.Contains(e.Location))
                                {
                                    mousedownobject_tmp = this.selectedItemsInfo[i];
                                    break;
                                }
                            }
                        }
                    }

                    this.mousedownobject = mousedownobject_tmp;
                }
            }

            base.OnMouseDown(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (!this.ReadOnly)
            {
                if (this.mousedownobject == null)
                {
                    object mouseenterobject_tmp = null;
                    if (this.ClearButtonVisible && this.clearbutton_rect.Contains(e.Location))
                    {
                        mouseenterobject_tmp = this.clearbutton_object;
                    }
                    else if (this.dropdrowbutton_rect.Contains(e.Location))
                    {
                        mouseenterobject_tmp = this.dropdrowbutton_object;
                    }

                    if (this.mouseenterobject != mouseenterobject_tmp)
                    {
                        this.mouseenterobject = mouseenterobject_tmp;
                        this.Invalidate();
                    }
                }
            }

            base.OnMouseMove(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (!this.ReadOnly)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (this.mousedownobject != null)
                    {
                        if (this.ClearButtonVisible && this.clearbutton_rect.Contains(e.Location))
                        {
                            if (this.mousedownobject == this.clearbutton_object && this.selectedItems.Count > 0)
                            {
                                this.SelectedItems = new List<DropDownListPlusItem>();
                            }
                        }
                        else if (this.dropdrowbutton_rect.Contains(e.Location) || (this.DropDownButton.OperateFullArea && !this.Multiple && this.content_rect.Contains(e.Location)))
                        {
                            if (this.mousedownobject == this.dropdrowbutton_object)
                            {
                                if (this.activatedIndex != -1)
                                {
                                    this.activatedIndex = 0;
                                    this.Invalidate();
                                }
                                this.ShowNativeWindow();
                            }
                        }
                        else if (this.Multiple && this.content_rect.Contains(e.Location))
                        {
                            DropDownListPlusItemInfo iteminfo = null;
                            for (int i = 0; i < this.selectedItemsInfo.Count; i++)
                            {
                                if (((DropDownListPlusItemInfo)this.selectedItemsInfo[i]).item_clearbutton_rect.Contains(e.Location))
                                {
                                    iteminfo = (DropDownListPlusItemInfo)this.selectedItemsInfo[i];
                                    break;
                                }
                            }
                            if (iteminfo != null)
                            {
                                this.selectedItems.Remove(iteminfo.item);
                                this.InitializeElement();
                                this.Invalidate();

                                this.OnSelectedItemsChanged(EventArgs.Empty);
                            }
                        }
                    }
                }
            }
            this.mousedownobject = null;
        }

        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (!this.ReadOnly)
            {
                switch (e.KeyData)
                {
                    case Keys.Left:
                    case Keys.Up:
                        {
                            if (!this.ReadOnly)
                            {
                                this.activatedState = true;

                                if (this.nativeWindow != null && this.nativeWindow.Visible)
                                {
                                    this.activatedIndex = 0;
                                }
                                else
                                {
                                    if (this.ClearButtonVisible)
                                    {
                                        this.activatedIndex += 1;
                                        if (this.activatedIndex > 1)
                                        {
                                            this.activatedIndex = 0;
                                        }
                                    }
                                    else
                                    {
                                        this.activatedIndex = 0;
                                    }
                                }
                                this.Invalidate();
                            }
                            break;
                        }
                    case Keys.Right:
                    case Keys.Down:
                        {
                            if (!this.ReadOnly)
                            {
                                this.activatedState = true;

                                if (this.nativeWindow != null && this.nativeWindow.Visible)
                                {
                                    this.activatedIndex = 0;
                                }
                                else
                                {
                                    if (this.ClearButtonVisible)
                                    {
                                        this.activatedIndex -= 1;
                                        if (this.activatedIndex < 0)
                                        {
                                            this.activatedIndex = 1;
                                        }
                                    }
                                    else
                                    {
                                        this.activatedIndex = 0;
                                    }
                                }
                                this.Invalidate();
                            }
                            break;
                        }
                    case Keys.Enter:
                        {
                            if (!this.ReadOnly)
                            {
                                Debug.Print(this.activatedIndex.ToString());
                                if (this.nativeWindow != null && this.nativeWindow.Visible)
                                {
                                    this.HideNativeWindow();
                                }
                                else
                                {
                                    if (this.activatedIndex == 0)
                                    {
                                        this.ShowNativeWindow();
                                    }
                                    else if (this.activatedIndex == 1)
                                    {
                                        this.SelectedItems = new List<DropDownListPlusItem>();
                                    }
                                }
                            }
                            break;
                        }
                }
            }

            base.OnKeyUp(e);
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            base.SetBoundsCore(x, y, width, this.GetControlAutoHeight(), specified);

            this.InitializeElementRectangle();
            this.SetControlShape();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.nativeWindow != null)
                {
                    this.nativeWindow.Hide();
                    this.nativeWindow.Dispose();
                    this.nativeWindow = null;
                }
            }
            base.Dispose(disposing);
        }

        #endregion

        #region 虚方法

        protected virtual void OnItemsSourceChanged(EventArgs e)
        {
            EventHandler handler = Events[EventItemsSourceChanged] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnSelectedItemsChanged(EventArgs e)
        {
            EventHandler handler = Events[EventSelectedItemsChanged] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnItemDrawBefore(DropDownListPlusItemDrawBeforeEventArgs e)
        {
            DropDownListPlusDrawItemBeforeEventHandler handler = Events[EventItemDrawBefore] as DropDownListPlusDrawItemBeforeEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnItemDrawAfter(DropDownListPlusItemDrawAfterEventArgs e)
        {
            DropDownListPlusDrawItemAfterEventHandler handler = Events[EventItemDrawAfter] as DropDownListPlusDrawItemAfterEventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 初始化控件内部元素布局
        /// </summary>
        public void InitializeElement()
        {
            this.SyncSelectedItemToSelectedItemInfo();
            this.CalculateSelectedItemInfoTextSize();
            this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, this.Height, BoundsSpecified.Size);
        }

        /// <summary>
        /// 绑定数据源
        /// </summary>
        /// <param name="source">要绑定数据源</param>
        public void BindItemsSource(DropDownListPlusItemCollection source)
        {
            if (this.nativeWindow != null && this.nativeWindow.Visible)
            {
                this.nativeWindow.Hide();
            }

            if (source == null)
                source = new DropDownListPlusItemCollection();

            if (this.itemsSourceCollection != null)
            {
                this.itemsSourceCollection.SetOwner(null);
                source.SetOwner(this);
            }
            this.itemsSourceCollection = source;

            this.selectedItems.Clear();
            this.SyncSelectedItemToSelectedItemInfo();
            this.InitializeElement();
            this.Invalidate();

            this.OnItemsSourceChanged(EventArgs.Empty);

        }

        /// <summary>
        /// 绑定数据源
        /// </summary>
        /// <param name="source">要绑定数据源</param>
        /// <param name="selectedItem">设置已选中选项(不会触发SelectedItemsChanged事件)</param>
        public void BindItemsSource(DropDownListPlusItemCollection source, DropDownListPlusItem selectedItem)
        {
            if (this.nativeWindow != null && this.nativeWindow.Visible)
            {
                this.nativeWindow.Hide();
            }

            if (source == null)
                source = new DropDownListPlusItemCollection();

            List<DropDownListPlusItem> items = new List<DropDownListPlusItem>();
            if (selectedItem != null)
            {
                items.Add(selectedItem);
            }

            if (this.itemsSourceCollection != null)
            {
                this.itemsSourceCollection.SetOwner(null);
                source.SetOwner(this);
            }
            this.itemsSourceCollection = source;

            this.selectedItems = items;
            this.SyncSelectedItemToSelectedItemInfo();
            this.InitializeElement();
            this.Invalidate();

            this.OnItemsSourceChanged(EventArgs.Empty);

        }

        /// <summary>
        /// 绑定数据源
        /// </summary>
        /// <param name="source">要绑定数据源</param>
        /// <param name="selectedItems">设置已选中选项集合(不会触发SelectedItemsChanged事件)</param>
        public void BindItemsSource(DropDownListPlusItemCollection source, List<DropDownListPlusItem> selectedItems)
        {
            if (this.nativeWindow != null && this.nativeWindow.Visible)
            {
                this.nativeWindow.Hide();
            }

            if (source == null)
                source = new DropDownListPlusItemCollection();

            if (selectedItems == null)
                selectedItems = new List<DropDownListPlusItem>();

            if (this.itemsSourceCollection != null)
            {
                this.itemsSourceCollection.SetOwner(null);
                source.SetOwner(this);
            }
            this.itemsSourceCollection = source;

            this.selectedItems = selectedItems;
            this.SyncSelectedItemToSelectedItemInfo();
            this.InitializeElement();
            this.Invalidate();

            this.OnItemsSourceChanged(EventArgs.Empty);

        }

        /// <summary>
        /// 鼠标是否进入选项
        /// </summary>
        /// <param name="item">鼠标是否进入选项</param>
        /// <returns></returns>
        internal bool IsMouseEnter(DropDownListPlusItem item)
        {
            if (item == null || this.nativeWindow == null)
                return false;

            int index = this.ItemsSource.IndexOf(item);
            if (index == -1)
                return false;

            return this.nativeWindow.IsMouseEnter(index);
        }

        #endregion

        #region 私有方法

        /// <summary>
        /// 更新控件元素rect
        /// </summary>
        private void InitializeElementRectangle()
        {
            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            int scale_font_occupied_height = font_metrics.GetFontStereotypesHeight();//字体占位高度，包括下划线和字体顶部补回空隙
            int scale_font_reality_height = font_metrics.GetFontRealHeight();//字体占位高度，删除下划线部分空隙
            int single_row_height = this.GetSingleRowHeight();
            int scale_clearbutton_width = (this.ClearButtonVisible && !this.ReadOnly) ? single_row_height : 0;

            this.dropdrowbutton_rect = new Rectangle(this.ClientRectangle.Right - single_row_height, this.ClientRectangle.Y, single_row_height, single_row_height);
            this.clearbutton_rect = new Rectangle(this.dropdrowbutton_rect.X - scale_clearbutton_width, this.ClientRectangle.Y, scale_clearbutton_width, single_row_height);
            this.content_rect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y + this.borderThicknes, Math.Max(0, (this.ClientRectangle.Width - this.dropdrowbutton_rect.Width - scale_clearbutton_width)), this.ClientRectangle.Height - this.borderThicknes * 2);

            if (this.Multiple)
            {
                int item_interval_space = +font_metrics.GetFontStereotypesMargim() * 6 / 4;
                int item_height = this.borderThicknes + item_interval_space + scale_font_reality_height + item_interval_space + this.borderThicknes;
                int item_image_c_size = scale_font_reality_height;
                int item_clearbutton_c_size = (this.Content.Item.ClearButtonVisible && !this.ReadOnly) ? item_height : 0;
                int count = 1;
                int content_left = this.ClientRectangle.X + this.borderThicknes + item_interval_space;
                int content_right = ((this.ClearButtonVisible && !this.ReadOnly) ? this.clearbutton_rect.X : this.dropdrowbutton_rect.X) - font_metrics.GetFontStereotypesMargim();
                int items_start_x = this.ClientRectangle.X;
                int current_x = items_start_x;

                for (int i = 0; i < this.selectedItemsInfo.Count; i++)
                {
                    DropDownListPlusItemInfo iteminfo = (DropDownListPlusItemInfo)this.selectedItemsInfo[i];
                    int item_width = this.borderThicknes + (this.Picker.Item.Icon.Visible ? item_height : 0) + font_metrics.GetFontStereotypesMargim() + iteminfo.item_text_size.Width + font_metrics.GetFontStereotypesMargim() + item_clearbutton_c_size + this.borderThicknes;

                    if (current_x == items_start_x)//行内第一个
                    {
                        iteminfo.item_rect = new Rectangle(content_left, this.ClientRectangle.Y + this.borderThicknes + count * item_interval_space + (count - 1) * item_height, item_width, item_height);
                        current_x += this.borderThicknes + item_interval_space + item_width;
                    }
                    else
                    {
                        if (current_x + item_interval_space + item_width <= content_right)
                        {
                            iteminfo.item_rect = new Rectangle(current_x + item_interval_space, this.ClientRectangle.Y + this.borderThicknes + count * item_interval_space + (count - 1) * item_height, item_width, item_height);
                            current_x += item_interval_space + item_width;
                        }
                        else
                        {
                            count++;
                            current_x = items_start_x;
                            iteminfo.item_rect = new Rectangle(content_left, this.ClientRectangle.Y + this.borderThicknes + count * item_interval_space + (count - 1) * item_height, item_width, item_height);
                            current_x += this.borderThicknes + item_interval_space + item_width;
                        }
                    }

                    if (this.Picker.Item.Icon.Visible)
                    {
                        iteminfo.item_image_rect = new Rectangle(iteminfo.item_rect.X + this.borderThicknes + item_interval_space, iteminfo.item_rect.Y + this.borderThicknes + item_interval_space, item_image_c_size, item_image_c_size);
                        iteminfo.item_text_rect = new Rectangle(iteminfo.item_image_rect.Right + item_interval_space, iteminfo.item_rect.Y + this.borderThicknes + item_interval_space, iteminfo.item_text_size.Width, iteminfo.item_text_size.Height);
                    }
                    else
                    {
                        iteminfo.item_image_rect = new Rectangle(iteminfo.item_rect.X + this.borderThicknes + item_interval_space, iteminfo.item_rect.Y + this.borderThicknes + item_interval_space, 0, item_image_c_size);
                        iteminfo.item_text_rect = new Rectangle(iteminfo.item_image_rect.Right + item_interval_space, iteminfo.item_rect.Y + this.borderThicknes + item_interval_space, iteminfo.item_text_size.Width, iteminfo.item_text_size.Height);
                    }
                    if (this.Content.Item.ClearButtonVisible && !this.ReadOnly)
                    {
                        iteminfo.item_clearbutton_rect = new Rectangle(iteminfo.item_rect.Right - this.borderThicknes - item_height, iteminfo.item_rect.Y, item_height, item_height);
                    }
                }

            }
        }

        /// <summary>
        /// 同步Item到ItemInfo
        /// </summary>
        private void SyncSelectedItemToSelectedItemInfo()
        {
            ArrayList iteminfoArr = new ArrayList();
            for (int i = 0; i < this.selectedItems.Count; i++)
            {
                iteminfoArr.Add(new DropDownListPlusItemInfo() { item = this.selectedItems[i] });
            }
            this.selectedItemsInfo = iteminfoArr;
        }

        /// <summary>
        /// 重新计算选中选项文本Size
        /// </summary>
        private void CalculateSelectedItemInfoTextSize()
        {
            // 更新选项元素Size
            if (this.selectedItems.Count > 0)
            {
                IntPtr hDC = IntPtr.Zero;
                Graphics g = null;
                ControlHelper.GetWindowClientGraphics(this.Handle, out g, out hDC);

                for (int i = 0; i < this.selectedItemsInfo.Count; i++)
                {
                    DropDownListPlusItemInfo iteminfo = (DropDownListPlusItemInfo)this.selectedItemsInfo[i];
                    iteminfo.item_text_size = Size.Ceiling(g.MeasureString(iteminfo.item.Text, this.Font, int.MaxValue, StringFormat.GenericTypographic));
                }

                g.Dispose();
                NativeMethods.ReleaseDC(this.Handle, hDC);
            }
        }

        /// <summary>
        /// 根据设置获取控件高度
        /// </summary>
        /// <returns></returns>
        private int GetControlAutoHeight()
        {
            int scale_padding_topbottom = (int)Math.Ceiling(this.Content.Padding * this.ScaleDpi);//内容区域上下内边距
            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            int scale_font_occupied_height = font_metrics.GetFontStereotypesHeight();//字体占位高度，包括下划线和字体顶部补回空隙
            int scale_font_reality_height = font_metrics.GetFontRealHeight();//字体占位高度，删除下划线部分空隙
            int scale_clearbutton_width = (this.ClearButtonVisible && !this.ReadOnly) ? this.GetSingleRowHeight() : 0;
            int item_interval_space = font_metrics.GetFontStereotypesMargim() * 6 / 4;
            int item_height = this.borderThicknes + item_interval_space + scale_font_reality_height + item_interval_space + this.borderThicknes;
            int item_clearbutton_c_size = (this.Content.Item.ClearButtonVisible && !this.ReadOnly) ? item_height : 0;

            if (this.Multiple)
            {
                int content_right = Math.Max(0, (this.ClientRectangle.Width - this.dropdrowbutton_rect.Width - scale_clearbutton_width)) - item_interval_space;
                int count = 1;
                int current_r = this.ClientRectangle.X;
                for (int i = 0; i < this.selectedItemsInfo.Count; i++)
                {
                    int item_width = this.borderThicknes + (this.Picker.Item.Icon.Visible ? item_height : 0) + font_metrics.GetFontStereotypesMargim() + ((DropDownListPlusItemInfo)this.selectedItemsInfo[i]).item_text_size.Width + font_metrics.GetFontStereotypesMargim() + item_clearbutton_c_size + this.borderThicknes;

                    current_r += item_interval_space + item_width;
                    if (current_r > content_right)
                    {
                        current_r = item_interval_space + item_width;
                        count++;
                    }
                }

                return this.borderThicknes + (count * item_height) + (count + 1) * item_interval_space + this.borderThicknes;
            }
            else
            {
                return this.borderThicknes + scale_padding_topbottom + scale_font_occupied_height + scale_padding_topbottom + this.borderThicknes;
            }
        }

        /// <summary>
        /// 获取控件单行高度
        /// </summary>
        /// <returns></returns>
        private int GetSingleRowHeight()
        {
            int scale_padding_topbottom = (int)Math.Ceiling(this.Content.Padding * this.ScaleDpi);//内容区域上下内边距
            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            int scale_font_occupied_height = font_metrics.GetFontStereotypesHeight();//字体占位高度，包括下划线和字体顶部补回空隙
            int scale_font_reality_height = font_metrics.GetFontRealHeight();//字体占位高度，删除下划线部分空隙

            if (this.Multiple)
            {
                int item_interval_space = +font_metrics.GetFontStereotypesMargim() * 6 / 4;
                int item_height = this.borderThicknes + item_interval_space + scale_font_reality_height + item_interval_space + this.borderThicknes;
                return this.borderThicknes + item_interval_space + item_height + item_interval_space + this.borderThicknes;
            }
            else
            {
                return this.borderThicknes + scale_padding_topbottom + scale_font_occupied_height + scale_padding_topbottom + this.borderThicknes;
            }
        }

        /// <summary>
        /// 设置控件形状
        /// </summary>
        private void SetControlShape()
        {
            GraphicsPath gp = this.AdjustControlShapePath();
            this.Region = new Region(gp);
            gp.Dispose();
        }

        /// <summary>
        /// 计算控件形状路径
        /// </summary>
        private GraphicsPath AdjustControlShapePath()
        {
            Rectangle rect = this.ClientRectangle;
            int single_row_height = this.GetSingleRowHeight();
            int dropdrow_width = this.content_rect.Right + 1;

            GraphicsPath path = new GraphicsPath();

            //当前为多行
            if (this.Multiple && this.ClientRectangle.Height > single_row_height)
            {
                if (this.RoundEnabled)
                {
                    path.AddPolygon(new Point[] {
                        new Point(rect.Left,rect.Top+1),
                        new Point(rect.Left+1,rect.Top+1),
                        new Point(rect.Left+1,rect.Top),

                        new Point(rect.Right-1,rect.Top),
                        new Point(rect.Right-1,rect.Top+1),
                        new Point(rect.Right,rect.Top+1),

                        new Point(rect.Right,single_row_height-1),
                        new Point(rect.Right-1,single_row_height-1),
                        new Point(rect.Right-1,single_row_height),

                        new Point(dropdrow_width,single_row_height),

                        new Point(dropdrow_width,rect.Bottom-1),
                        new Point(dropdrow_width-1,rect.Bottom-1),
                        new Point(dropdrow_width-1,rect.Bottom),

                        new Point(rect.Left+1,rect.Bottom),
                        new Point(rect.Left+1,rect.Bottom-1),
                        new Point(rect.Left,rect.Bottom-1),
                    });
                }
                else
                {
                    path.AddPolygon(new Point[] {
                        new Point(rect.Left, rect.Top),
                        new Point(rect.Right, rect.Top),
                        new Point(rect.Right, single_row_height),
                        new Point(dropdrow_width, single_row_height),
                        new Point(dropdrow_width, rect.Bottom),
                        new Point(rect.Left, rect.Bottom)
                    });
                }
            }
            //当前为单行
            else
            {
                if (this.RoundEnabled)
                {
                    path.AddPolygon(new Point[] {
                        new Point(rect.Left,rect.Top+1),
                        new Point(rect.Left+1,rect.Top+1),
                        new Point(rect.Left+1,rect.Top),

                        new Point(rect.Right-1,rect.Top),
                        new Point(rect.Right-1,rect.Top+1),
                        new Point(rect.Right,rect.Top+1),

                        new Point(rect.Right,rect.Bottom-1),
                        new Point(rect.Right-1,rect.Bottom-1),
                        new Point(rect.Right-1,rect.Bottom),

                        new Point(rect.Left+1,rect.Bottom),
                        new Point(rect.Left+1,rect.Bottom-1),
                        new Point(rect.Left,rect.Bottom-1),
                    });
                }
                else
                {
                    path.AddRectangle(rect);
                }
            }

            return path;
        }

        /// <summary>
        /// 绘制Rectangle 1个像素边框（圆角边框半径为3个像素）
        /// </summary>
        /// <param name="g">要绘制边框的控件画布</param>
        /// <param name="borderColor">边框颜色</param>
        /// <param name="borderOutOverColor">父控件背景色（圆角边框平滑过度颜色）</param>
        /// <param name="borderInOverColor">控件背景色（圆角边框平滑过度颜色）</param>
        private void DrawControlBorder(Graphics g, Color borderColor, Color borderOutOverColor, Color borderInOverColor)
        {
            Rectangle rect = this.ClientRectangle;
            int single_row_height = this.GetSingleRowHeight();
            int dropdrow_width = this.content_rect.Right + 1;

            SmoothingMode smoothingMode = g.SmoothingMode;
            CompositingMode compositingMode = g.CompositingMode;
            CompositingQuality compositingQuality = g.CompositingQuality;
            InterpolationMode interpolationMode = g.InterpolationMode;

            g.SmoothingMode = SmoothingMode.None;
            g.CompositingMode = CompositingMode.SourceCopy;
            g.CompositingQuality = CompositingQuality.Default;
            g.InterpolationMode = InterpolationMode.Default;

            Pen border_pen = new Pen(borderColor);

            //当前为多行
            if (this.Multiple && this.ClientRectangle.Height > single_row_height)
            {
                if (this.RoundEnabled)
                {
                    //边框
                    g.DrawPolygon(border_pen, new Point[] {
                        new Point(rect.Left,rect.Top+1),
                        new Point(rect.Left+1,rect.Top+1),
                        new Point(rect.Left+1,rect.Top),

                        new Point(rect.Right-1-1,rect.Top),
                        new Point(rect.Right-1-1,rect.Top+1),
                        new Point(rect.Right-1,rect.Top+1),

                        new Point(rect.Right-1,single_row_height-1-1),
                        new Point(rect.Right-1-1,single_row_height-1-1),
                        new Point(rect.Right-1-1,single_row_height-1),

                        new Point(dropdrow_width-1,single_row_height-1),

                        new Point(dropdrow_width-1,rect.Bottom-1-1),
                        new Point(dropdrow_width-1-1,rect.Bottom-1-1),
                        new Point(dropdrow_width-1-1,rect.Bottom-1),

                        new Point(rect.Left+1,rect.Bottom-1),
                        new Point(rect.Left+1,rect.Bottom-1-1),
                        new Point(rect.Left,rect.Bottom-1-1),
                    });

                    //边框圆角外平滑过度
                    border_pen.Color = Color.FromArgb(borderColor.R + (borderOutOverColor.R - borderColor.R) / 4, borderColor.G + (borderOutOverColor.G - borderColor.G) / 4, borderColor.B + (borderOutOverColor.B - borderColor.B) / 4);
                    g.DrawLine(border_pen, new Point(rect.Left, rect.Top + 1), new Point(rect.Left + 1, rect.Top));
                    g.DrawLine(border_pen, new Point(rect.Right - 2, rect.Top), new Point(rect.Right - 1, rect.Top + 1));
                    g.DrawLine(border_pen, new Point(rect.Right - 1, single_row_height - 2), new Point(rect.Right - 2, single_row_height - 1));
                    g.DrawLine(border_pen, new Point(dropdrow_width - 1, rect.Bottom - 2), new Point(dropdrow_width - 2, rect.Bottom - 1));
                    g.DrawLine(border_pen, new Point(rect.Left + 1, rect.Bottom - 1), new Point(rect.Left, rect.Bottom - 2));

                    //边框圆角内平滑过度
                    SolidBrush sb = new SolidBrush(Color.FromArgb((borderColor.R + borderInOverColor.R) / 2, (borderColor.G + borderInOverColor.G) / 2, (borderColor.B + borderInOverColor.B) / 2));
                    g.FillRectangle(sb, new Rectangle(rect.Left + 1, rect.Top + 1, 1, 1));
                    g.FillRectangle(sb, new Rectangle(rect.Right - 2, rect.Top + 1, 1, 1));
                    g.FillRectangle(sb, new Rectangle(rect.Right - 2, single_row_height - 2, 1, 1));
                    g.FillRectangle(sb, new Rectangle(dropdrow_width - 2, rect.Bottom - 2, 1, 1));
                    g.FillRectangle(sb, new Rectangle(rect.Left + 1, rect.Bottom - 2, 1, 1));
                    sb.Dispose();
                }
                else
                {
                    g.DrawPolygon(border_pen, new Point[] {
                        new Point(rect.Left, rect.Top),
                        new Point(rect.Right-1, rect.Top),
                        new Point(rect.Right-1, single_row_height-1),
                        new Point(dropdrow_width-1, single_row_height-1),
                        new Point(dropdrow_width-1, rect.Bottom-1),
                        new Point(rect.Left, rect.Bottom-1)
                    });
                }
            }
            //当前为单行
            else
            {
                if (this.RoundEnabled)
                {
                    //边框
                    g.DrawPolygon(border_pen, new Point[] {
                        new Point(rect.Left,rect.Top+1),
                        new Point(rect.Left+1,rect.Top+1),
                        new Point(rect.Left+1,rect.Top),

                        new Point(rect.Right-1-1,rect.Top),
                        new Point(rect.Right-1-1,rect.Top+1),
                        new Point(rect.Right-1,rect.Top+1),

                        new Point(rect.Right-1,rect.Bottom-1-1),
                        new Point(rect.Right-1-1,rect.Bottom-1-1),
                        new Point(rect.Right-1-1,rect.Bottom-1),

                        new Point(rect.Left+1,rect.Bottom-1),
                        new Point(rect.Left+1,rect.Bottom-1-1),
                        new Point(rect.Left,rect.Bottom-1-1),
                    });

                    //边框圆角外平滑过度
                    border_pen.Color = Color.FromArgb(borderColor.R + (borderOutOverColor.R - borderColor.R) / 4, borderColor.G + (borderOutOverColor.G - borderColor.G) / 4, borderColor.B + (borderOutOverColor.B - borderColor.B) / 4);
                    g.DrawLine(border_pen, new Point(rect.Left, rect.Top + 1), new Point(rect.Left + 1, rect.Top));
                    g.DrawLine(border_pen, new Point(rect.Right - 2, rect.Top), new Point(rect.Right - 1, rect.Top + 1));
                    g.DrawLine(border_pen, new Point(rect.Right - 1, rect.Bottom - 2), new Point(rect.Right - 2, rect.Bottom - 1));
                    g.DrawLine(border_pen, new Point(rect.Left + 1, rect.Bottom - 1), new Point(rect.Left, rect.Bottom - 2));

                    //边框圆角内平滑过度
                    SolidBrush sb = new SolidBrush(Color.FromArgb((borderColor.R + borderInOverColor.R) / 2, (borderColor.G + borderInOverColor.G) / 2, (borderColor.B + borderInOverColor.B) / 2));
                    g.FillRectangle(sb, new Rectangle(rect.Left + 1, rect.Top + 1, 1, 1));
                    g.FillRectangle(sb, new Rectangle(rect.Right - 2, rect.Top + 1, 1, 1));
                    g.FillRectangle(sb, new Rectangle(rect.Right - 2, rect.Bottom - 2, 1, 1));
                    g.FillRectangle(sb, new Rectangle(rect.Left + 1, rect.Bottom - 2, 1, 1));
                    sb.Dispose();
                }
                else
                {
                    g.DrawRectangle(border_pen, new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
                }
            }

            border_pen.Dispose();

            g.SmoothingMode = smoothingMode;
            g.CompositingMode = compositingMode;
            g.CompositingQuality = compositingQuality;
            g.InterpolationMode = interpolationMode;
        }

        /// <summary>
        /// 判断两个集合是否一致(不包括顺序)
        /// </summary>
        /// <param name="list1">集合1</param>
        /// <param name="list2">集合2</param>
        /// <returns></returns>
        private bool IsEqualList(List<DropDownListPlusItem> list1, List<DropDownListPlusItem> list2)
        {
            if (list1 == null)
                list1 = new List<DropDownListPlusItem>();
            if (list2 == null)
                list2 = new List<DropDownListPlusItem>();

            if (list1.Count != list2.Count)
                return false;

            for (int i = 0; i < list1.Count; i++)
            {
                if (list1[i] != list2[i])
                {
                    return false;
                }
            }

            return true;
        }

        /// <summary>
        /// 显示下拉列表弹层（同时安装钩子）
        /// </summary>
        private void ShowNativeWindow()
        {
            if (this.nativeWindow == null)
            {
                this.nativeWindow = new DropDownListPlusNativeWindow(this);
            }
            if (!this.nativeWindow.Visible)
            {
                this.nativeWindow.SelectedItems = new List<DropDownListPlusItem>();
                for (int i = 0; i < this.selectedItems.Count; i++)
                {
                    this.nativeWindow.SelectedItems.Add(this.selectedItems[i]);
                }

                this.nativeWindow.Show();
            }

        }

        /// <summary>
        /// 隐藏下拉列表弹层（同时同步下拉列表选中选项和取消钩子）
        /// </summary>
        private void HideNativeWindow()
        {
            if (this.nativeWindow != null && this.nativeWindow.Visible)
            {
                this.SelectedItems = this.nativeWindow.SelectedItems;
                this.nativeWindow.Hide();
            }
        }

        #endregion

        #region 类

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class ContentObject
        {
            private DropDownListPlus owner = null;
            internal ContentObject(DropDownListPlus owner) { this.owner = owner; }

            #region 属性

            private int padding = 3;
            /// <summary>
            /// 选项区域上下内边距(只限于单选模式)
            /// </summary>
            [Description("选项区域上下内边距(只限于单选模式)")]
            [PropertyOrder(-195)]
            [DefaultValue(3)]
            public int Padding
            {
                get { return this.padding; }
                set
                {
                    if (this.padding == value || value < 0)
                        return;

                    this.padding = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeElement();
                        this.owner.Invalidate();
                    }
                }
            }

            private string nullTipText = "";
            /// <summary>
            /// 空值提示文本
            /// </summary>
            [Description("空值提示文本")]
            [PropertyOrder(-194)]
            [DefaultValue("")]
            public string NullTipText
            {
                get { return this.nullTipText; }
                set
                {
                    if (this.nullTipText == value)
                        return;

                    this.nullTipText = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private ItemObject item;
            /// <summary>
            /// 选项
            /// </summary>
            [Description("选项")]
            [PropertyOrder(-191)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ItemObject Item
            {
                get
                {
                    if (this.item == null)
                        this.item = new ItemObject(this.owner);
                    return this.item;
                }
            }

            #endregion

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class ItemObject
            {
                private DropDownListPlus owner = null;
                internal ItemObject(DropDownListPlus owner) { this.owner = owner; }

                #region 属性

                private bool clearButtonVisible = false;
                /// <summary>
                /// 选项是否显示清除按钮
                /// </summary>
                [Description("选项是否显示清除按钮")]
                [PropertyOrder(-193)]
                [DefaultValue(false)]
                public bool ClearButtonVisible
                {
                    get { return this.clearButtonVisible; }
                    set
                    {
                        if (this.clearButtonVisible == value)
                            return;

                        this.clearButtonVisible = value;
                        if (this.owner != null)
                        {
                            this.owner.InitializeElement();
                            this.owner.Invalidate();
                        }
                    }
                }

                #endregion

            }

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class DropDownButtonObject
        {
            private DropDownListPlus owner = null;
            internal DropDownButtonObject(DropDownListPlus owner) { this.owner = owner; }

            #region 属性

            private bool operateFullArea = false;
            /// <summary>
            /// 下拉按钮的有效区域是否为整个控件（只限于单选模式）
            /// </summary>
            [Description("下拉按钮的有效区域是否为整个控件（只限于单选模式）")]
            [PropertyOrder(-194)]
            [DefaultValue(false)]
            public bool OperateFullArea
            {
                get { return this.operateFullArea; }
                set
                {
                    if (this.operateFullArea == value)
                        return;

                    this.operateFullArea = value;
                }
            }

            #endregion

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class PickerObject
        {
            private DropDownListPlus owner = null;
            internal PickerObject(DropDownListPlus owner) { this.owner = owner; }

            #region 属性

            private DropDownListPlusPickerStylePattern stylePattern = DropDownListPlusPickerStylePattern.StraightLine;
            /// <summary>
            /// 风格模式
            /// </summary>
            [Description("风格模式")]
            [PropertyOrder(-200)]
            [DefaultValue(DropDownListPlusPickerStylePattern.StraightLine)]
            public DropDownListPlusPickerStylePattern StylePattern
            {
                get { return this.stylePattern; }
                set
                {
                    if (this.stylePattern == value)
                        return;

                    this.stylePattern = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int roundSize = 6;
            /// <summary>
            /// 圆角Size
            /// </summary>
            [Description("圆角Size")]
            [PropertyOrder(-198)]
            [DefaultValue(6)]
            public int RoundSize
            {
                get { return this.roundSize; }
                set
                {
                    if (value < 1)
                        value = 1;
                    if (this.roundSize == value)
                        return;

                    this.roundSize = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int maxHeight = 0;
            /// <summary>
            /// 下拉面板最大高度（0为自动计算）
            /// </summary>
            [Description("下拉面板最大高度（0为自动计算）")]
            [PropertyOrder(-194)]
            [DefaultValue(0)]
            public int MaxHeight
            {
                get { return this.maxHeight; }
                set
                {
                    if (this.maxHeight == value || value <= 0)
                        return;

                    this.maxHeight = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private bool locateVisible = false;
            /// <summary>
            /// 已选中选项是否显示定位
            /// </summary>
            [Description("已选中选项是否显示定位")]
            [PropertyOrder(-190)]
            [DefaultValue(false)]
            public bool LocateVisible
            {
                get { return this.locateVisible; }
                set
                {
                    if (this.locateVisible == value)
                        return;

                    this.locateVisible = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private string nullTipText = "";
            /// <summary>
            /// 空数据源提示文本
            /// </summary>
            [Description("空数据源提示文本")]
            [PropertyOrder(-186)]
            [DefaultValue("")]
            public string NullTipText
            {
                get { return this.nullTipText; }
                set
                {
                    if (this.nullTipText == value)
                        return;

                    this.nullTipText = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private ItemObject item;
            /// <summary>
            /// 选项
            /// </summary>
            [Description("选项")]
            [PropertyOrder(-180)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ItemObject Item
            {
                get
                {
                    if (this.item == null)
                        this.item = new ItemObject(this.owner);
                    return this.item;
                }
            }

            private ScrollBarObject scrollBar;
            /// <summary>
            /// 滚动条
            /// </summary>
            [Description("滚动条")]
            [PropertyOrder(-178)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ScrollBarObject ScrollBar
            {
                get
                {
                    if (this.scrollBar == null)
                        this.scrollBar = new ScrollBarObject(this.owner);
                    return this.scrollBar;
                }
            }


            #endregion

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class ItemObject
            {
                private DropDownListPlus owner = null;
                internal ItemObject(DropDownListPlus owner) { this.owner = owner; }

                #region 属性

                private TBPadding tBPadding = new TBPadding(8, 8);
                /// <summary>
                /// 上下内边距
                /// </summary>
                [Description("上下内边距")]
                [Category("杂项")]
                [PropertyOrder(-190)]
                [DefaultValue(typeof(TBPadding), "8, 8")]
                public TBPadding TBPadding
                {
                    get { return this.tBPadding; }
                    set
                    {
                        if (value.Top < 0)
                            value.Top = 0;
                        if (value.Bottom < 0)
                            value.Bottom = 0;
                        if (this.tBPadding == value)
                            return;

                        this.tBPadding = value;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }

                private LRPadding lRPadding = new LRPadding(4, 4);
                /// <summary>
                /// 左右内边距
                /// </summary>
                [Description("左右内边距")]
                [Category("杂项")]
                [PropertyOrder(-180)]
                [DefaultValue(typeof(LRPadding), "4, 4")]
                public LRPadding LRPadding
                {
                    get { return this.lRPadding; }
                    set
                    {
                        if (value.Left < 0)
                            value.Left = 0;
                        if (value.Right < 0)
                            value.Right = 0;
                        if (this.lRPadding == value)
                            return;

                        this.lRPadding = value;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }

                private IconObject icon;
                /// <summary>
                /// 图标
                /// </summary>
                [Description("图标")]
                [Category("杂项")]
                [PropertyOrder(-174)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                public IconObject Icon
                {
                    get
                    {
                        if (this.icon == null)
                            this.icon = new IconObject(this.owner);
                        return this.icon;
                    }
                }

                #endregion

                [TypeConverter(typeof(PropertyOrderConverter))]
                public class IconObject
                {
                    private DropDownListPlus owner = null;
                    internal IconObject(DropDownListPlus owner) { this.owner = owner; }

                    #region 属性

                    private bool visible = false;
                    /// <summary>
                    /// 是否显示图片
                    /// </summary>
                    [Description("是否显示图片")]
                    [PropertyOrder(-160)]
                    [DefaultValue(false)]
                    public bool Visible
                    {
                        get { return this.visible; }
                        set
                        {
                            if (this.visible == value)
                                return;

                            this.visible = value;
                            if (this.owner != null)
                            {
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private Size size = new Size(18, 18);
                    /// <summary>
                    /// 图片Size
                    /// </summary>
                    [Description("图片Size")]
                    [PropertyOrder(-158)]
                    [DefaultValue(typeof(Size), "18,18")]
                    public Size Size
                    {
                        get { return this.size; }
                        set
                        {
                            if (value.Width <= 0)
                                value.Width = 0;
                            if (value.Height <= 0)
                                value.Height = 0;
                            if (this.size == value)
                                return;

                            this.size = value;
                            if (this.owner != null)
                            {
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private LRMargin lRMargin = new LRMargin(4, 4);
                    /// <summary>
                    /// 图片左右外边距
                    /// </summary>
                    [Description("图片左右外边距")]
                    [PropertyOrder(-157)]
                    [DefaultValue(typeof(LRMargin), "4, 4")]
                    public LRMargin LRMargin
                    {
                        get { return this.lRMargin; }
                        set
                        {
                            if (value.Left < 0)
                                value.Left = 0;
                            if (value.Right < 0)
                                value.Right = 0;
                            if (this.lRMargin == value)
                                return;

                            this.lRMargin = value;
                            if (this.owner != null)
                            {
                                this.owner.Invalidate();
                            }
                        }
                    }

                    private Image image = null;
                    /// <summary>
                    /// 图片
                    /// </summary>
                    [Description("图片")]
                    [PropertyOrder(-156)]
                    [DefaultValue(null)]
                    [RefreshProperties(RefreshProperties.Repaint)]
                    public Image Image
                    {
                        get { return this.image; }
                        set
                        {
                            if (this.image == value)
                                return;

                            this.image = value;
                            if (this.owner != null)
                            {
                                this.owner.Invalidate();
                            }
                        }
                    }

                    #endregion

                }

            }

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class ScrollBarObject
            {
                private DropDownListPlus owner = null;
                internal ScrollBarObject(DropDownListPlus owner) { this.owner = owner; }

                #region 属性

                private int trackThickness = 12;
                /// <summary>
                /// 轨道厚度
                /// </summary>
                [Description("轨道厚度")]
                [PropertyOrder(-140)]
                [DefaultValue(12)]
                public int TrackThickness
                {
                    get { return this.trackThickness; }
                    set
                    {
                        if (this.trackThickness == value || value < 0)
                            return;

                        this.trackThickness = value;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }

                private int thumbMinSize = 26;
                /// <summary>
                /// 拇指最小高度
                /// </summary>
                [Description("拇指最小高度")]
                [PropertyOrder(-138)]
                [DefaultValue(26)]
                public int ThumbMinSize
                {
                    get { return this.thumbMinSize; }
                    set
                    {
                        if (this.thumbMinSize == value || value < 1)
                            return;

                        this.thumbMinSize = value;
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }

                #endregion

            }

        }



        /// <summary>
        /// 下拉列表弹层NativeWindow
        /// 
        /// 提供窗口句柄和窗口过程的低级封装
        /// NativeWindow 使用局部鼠标钩子来处理鼠标事件，放弃原有鼠标默认鼠标事件，因为要添加窗体自动消失功能，
        /// 使用分层窗体为例能绘制透明，同时在工作区域模拟非工作区部分。
        /// 
        /// </summary>
        internal class DropDownListPlusNativeWindow : NativeWindow, IDisposable
        {
            #region 属性

            /// <summary>
            /// 下拉列表弹层的显示状态
            /// </summary>
            public bool Visible
            {
                get
                {
                    if (this.Handle == IntPtr.Zero)
                        return false;

                    return NativeMethods.IsWindowVisible(this.Handle);
                }
            }

            /// <summary>
            /// 控件大小和位置（包括其非工作区元素）
            /// </summary>
            public Rectangle Bounds
            {
                get
                {
                    if (this.Handle == IntPtr.Zero)
                        return Rectangle.Empty;

                    NativeMethods.RECT r = new NativeMethods.RECT();
                    NativeMethods.GetWindowRect(this.Handle, ref r);
                    return new Rectangle(r.left, r.top, r.right - r.left, r.bottom - r.top);
                }
            }

            /// <summary>
            /// 控件工作区域大小和位置（模仿）
            /// </summary>
            protected Rectangle ClientBounds
            {
                get
                {
                    if (this.Handle == IntPtr.Zero)
                        return Rectangle.Empty;

                    Rectangle rect = this.Bounds;
                    int scale_roundedCorner = (this.owner == null) ? 0 : (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi);
                    return new Rectangle(scale_roundedCorner, (int)(scale_roundedCorner / 3f), rect.Width - scale_roundedCorner * 2, rect.Height - scale_roundedCorner * 2);
                }
            }

            /// <summary>
            /// 控件工作区域（模仿）
            /// </summary>
            public Rectangle ClientRectangle
            {
                get
                {
                    if (this.Handle == IntPtr.Zero)
                        return Rectangle.Empty;

                    Rectangle rect = this.Bounds;
                    int scale_roundedCorner = (this.owner == null) ? 0 : (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi);
                    return new Rectangle(0, 0, rect.Width - scale_roundedCorner * 2, rect.Height - scale_roundedCorner * 2);
                }
            }

            /// <summary>
            /// 控件当前滚动条是否显示
            /// </summary>
            public bool ScrollVisible
            {
                get
                {
                    if (this.owner == null || this.Handle == IntPtr.Zero)
                        return false;

                    return (this.GetItemsRealityHeight() > this.ClientRectangle.Height);
                }
            }

            private List<DropDownListPlusItem> selectedItemsCollection = new List<DropDownListPlusItem>();
            /// <summary>
            /// 下拉列表弹层已选中集合
            /// </summary>
            [Browsable(false)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal List<DropDownListPlusItem> SelectedItems
            {
                get { return this.selectedItemsCollection; }
                set { this.selectedItemsCollection = value; }
            }

            #endregion

            #region 字段

            /// <summary>
            /// 下拉列表弹层拥有者
            /// </summary>
            private DropDownListPlus owner = null;
            /// <summary>
            /// 下拉列表弹层四边阴影图片缓存
            /// </summary>
            private Bitmap shadow_image_tmp = null;


            /// <summary>
            /// 鼠标钩子拥有者
            /// </summary>
            private static DropDownListPlusNativeWindow hook_owner = null;
            /// <summary>
            /// 鼠标钩子回调函数
            /// </summary>
            private HookProc hook_callback = null;
            /// <summary>
            /// 钩子id集合
            /// </summary>
            private static ArrayList hook_id_array = new ArrayList();
            /// <summary>
            /// 钩子id
            /// </summary>
            private int hook_id = 0;
            /// <summary>
            /// 鼠标钩子回调委托
            /// </summary>
            /// <param name="nCode"></param>
            /// <param name="wParam"></param>
            /// <param name="lParam"></param>
            /// <returns></returns>
            public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
            /// <summary>
            /// 鼠标钩子返回信息结构体
            /// </summary>
            [StructLayout(LayoutKind.Sequential)]
            public class MouseHookStruct
            {
                public PointStruct pt;
                public int hwnd;
                public int wHitTestCode;
                public int dwExtraInfo;
            }
            /// <summary>
            /// 鼠标钩子坐标
            /// </summary>
            [StructLayout(LayoutKind.Sequential)]
            public struct PointStruct
            {
                public int X;
                public int Y;
            }


            /// <summary>
            /// 鼠标是否在控件模拟工作区范围内 (WndProc消息)
            /// </summary>
            private bool wndproc_ismousein = false;
            /// <summary>
            /// 鼠标是否在控件模拟工作区范围内按下过 (WndProc消息)
            /// </summary>
            private bool wndproc_mousepressed = false;


            /// <summary>
            /// 当前鼠标已按下的对象(-2 滚动条、-1没有、>=0 下拉列表选项)
            /// </summary>
            private int mousedownindex = -1;
            /// <summary>
            /// 鼠标按下功能坐标
            /// </summary>
            private Point mousedownpoint = Point.Empty;
            /// <summary>
            /// 鼠标按下滚动条时菜单真实区的Y坐标
            /// </summary>
            private int mousedown_scrollOffsetY = 0;
            /// <summary>
            /// 鼠标进入对象
            /// </summary>
            private int mouseenterindex = -1;


            /// <summary>
            /// 滚动条轨道Rect
            /// </summary>
            public Rectangle scrollTrackRect = Rectangle.Empty;
            /// <summary>
            /// 滚动条拇指rect
            /// </summary>
            public Rectangle scrollThumbRect = Rectangle.Empty;
            /// <summary>
            /// 滚动条拇指Y轴距离(存放内容Y轴真实距离)
            /// </summary>
            private int scrollOffsetY = 0;

            /// <summary>
            /// 选项高度
            /// </summary>
            private int item_height = 0;

            #endregion

            #region 扩展

            private const int SWP_NOSIZE = 0x0001;
            private const int SWP_NOMOVE = 0x0002;
            private const int SWP_NOZORDER = 0x0004;
            private const int SWP_NOACTIVATE = 0x0010;
            private const int SWP_SHOWWINDOW = 0x0040;
            private const int SWP_HIDEWINDOW = 0x0080;
            private const int WM_GETOBJECT = 0x003D;
            private const int WM_SETCURSOR = 0x0020;
            private const int WM_MOUSEWHEEL = 0x020A;
            private const int WM_MOUSEACTIVATE = 0x0021;//鼠标激活窗体
            private const int MA_NOACTIVATE = 3;// 不激活窗口，但也不会放弃鼠标消息

            private const int WH_MOUSE = 14;
            private const int WM_LBUTTONDOWN = 0x0201;
            private const int WM_MBUTTONDOWN = 0x0207;
            private const int WM_RBUTTONDOWN = 0x0204;
            private const int WM_NCLBUTTONDOWN = 0x00A1;
            private const int WM_NCRBUTTONDOWN = 0x00A4;
            private const int WM_NCMBUTTONDOWN = 0x00A7;
            private const int WM_LBUTTONUP = 0x0202;
            private const int WM_MOUSEMOVE = 0x0200;

            private const int WS_CAPTION = 0x00C00000;
            private const int WS_CLIPSIBLINGS = 0x04000000;
            private const int WS_POPUP = unchecked((int)0x80000000);
            private const int WS_EX_APPWINDOW = 0x00040000;
            private const int WS_EX_CONTROLPARENT = 0x00010000;
            private const int WS_EX_TOOLWINDOW = 0x00000080;
            private const int WS_EX_LAYERED = 0x80000;
            private const int CS_SAVEBITS = 0x0800;
            private const int GWL_EXSTYLE = (-20);

            private const int ULW_ALPHA = 0x00000002;//使用 pblend 作為混合函式
            private const byte AC_SRC_OVER = 0;//定義要執行的混合作業
            private const byte AC_SRC_ALPHA = 1;//混合作業方式

            [StructLayout(LayoutKind.Sequential, Pack = 1)]
            public struct BLENDFUNCTION
            {
                public byte BlendOp;
                public byte BlendFlags;
                public byte SourceConstantAlpha;
                public byte AlphaFormat;
            }

            [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern IntPtr GetDC(IntPtr hWnd);

            [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

            [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

            [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern int DeleteDC(IntPtr hdc);

            [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern IntPtr SelectObject(IntPtr hdc, IntPtr h);

            [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern int DeleteObject(IntPtr ho);

            [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
            public static extern int UpdateLayeredWindow(IntPtr hWnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pptSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);

            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
            public static extern int SetWindowsHookEx(int hookid, HookProc pfnhook, IntPtr hinst, int threadid);

            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
            public static extern bool UnhookWindowsHookEx(int idHook);

            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
            public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr GetModuleHandle(string modName);

            #endregion

            public DropDownListPlusNativeWindow(DropDownListPlus owner)
            {
                //设置弹层拥有者
                this.owner = owner;

                //设置窗体样式（分层窗体、禁止出现在导航列表）
                CreateParams cp = new CreateParams();
                cp.Style &= ~(WS_CAPTION | WS_CLIPSIBLINGS);
                cp.ExStyle &= ~(WS_EX_APPWINDOW);
                cp.Style |= WS_POPUP;
                cp.ExStyle |= (WS_EX_CONTROLPARENT);
                cp.ExStyle |= WS_EX_LAYERED;
                cp.ClassStyle |= CS_SAVEBITS;

                //创建控件句柄
                this.CreateHandle(cp);

                //禁止出啊现在任务栏
                int flags = unchecked((int)(long)NativeMethods.GetWindowLong(this.Handle, GWL_EXSTYLE)) | WS_EX_TOOLWINDOW;
                NativeMethods.SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)flags);

            }

            #region 重写

            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);

                switch (m.Msg)
                {
                    case WM_MOUSEACTIVATE://禁止激活窗体但接受鼠标事件
                        {
                            m.Result = new IntPtr(MA_NOACTIVATE);
                            return;
                        }
                    case WM_MOUSEWHEEL://鼠标滚轮滚动
                        {
                            this.DefWndProc(ref m);

                            Point point = new Point(NativeMethods.SignedLOWORD(m.LParam), NativeMethods.SignedHIWORD(m.LParam));
                            this.WmMouseWheel(this.owner, new MouseEventArgs(MouseButtons.None, 0, point.X, point.Y, (short)NativeMethods.SignedHIWORD(m.WParam)));

                            break;
                        }
                    case WM_SETCURSOR://设置光标
                        {
                            DefWndProc(ref m);

                            Cursor cursor = this.owner == null ? Cursors.Default : this.owner.Cursor;
                            if (Cursor.Current != cursor)
                            {
                                Cursor.Current = cursor;
                            }

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEENTER:// 鼠标进入
                        {
                            Point point = new Point(NativeMethods.SignedLOWORD(m.LParam), NativeMethods.SignedHIWORD(m.LParam));
                            this.WmMouseEnter(this, new MouseEventArgs(MouseButtons.None, 0, point.X, point.Y, 0));

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSELEAVE:// 鼠标离开
                        {
                            Point point = new Point(NativeMethods.SignedLOWORD(m.LParam), NativeMethods.SignedHIWORD(m.LParam));
                            this.WmMouseLeave(this, new MouseEventArgs(MouseButtons.None, 0, point.X, point.Y, 0));

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEDOWN://鼠标左键按下
                        {
                            Point point = new Point(NativeMethods.SignedLOWORD(m.LParam), NativeMethods.SignedHIWORD(m.LParam));
                            this.WmMouseDown(this, new MouseEventArgs(MouseButtons.Left, 1, point.X, point.Y, 0));

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEUP://鼠标左键释放
                        {
                            Point point = new Point(NativeMethods.SignedLOWORD(m.LParam), NativeMethods.SignedHIWORD(m.LParam));
                            this.WmMouseUp(this, new MouseEventArgs(MouseButtons.Left, 1, point.X, point.Y, 0));

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEMOVE://鼠标移动
                        {
                            Point point = new Point(NativeMethods.SignedLOWORD(m.LParam), NativeMethods.SignedHIWORD(m.LParam));
                            this.WmMouseMove(this, new MouseEventArgs(MouseButtons.None, 0, point.X, point.Y, 0));

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_CLOSED://下拉列表弹层关闭
                        {
                            this.WmClosed(this, EventArgs.Empty);

                            break;
                        }
                    case NativeMethods.WM_USER_DROPDROWLISTPLUS_PAINT://绘制分层窗体
                        {
                            if (this.Handle != IntPtr.Zero && this.owner != null || this.Visible)
                            {
                                //创建画布
                                Bitmap bmp = new Bitmap(this.Bounds.Width, this.Bounds.Height);
                                Graphics g = Graphics.FromImage(bmp);
                                //绘制（模仿非工作区）
                                PaintEventArgs nc_arg = new PaintEventArgs(g, new Rectangle(0, 0, this.Bounds.Width, this.Bounds.Height));
                                this.WmNCPaint(this, nc_arg);
                                //绘制（模仿工作区）
                                GraphicsPath client_path = new GraphicsPath();
                                client_path.AddPath(ControlHelper.AdjustCircularPath(this.ClientBounds, (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi)), true);

                                g.SetClip(client_path);
                                g.TranslateTransform(this.ClientBounds.X, this.ClientBounds.Y); //修改系统坐标为模仿工作区坐标
                                this.WmPaint(this, new PaintEventArgs(g, this.ClientRectangle));
                                g.ResetClip();
                                client_path.Dispose();
                                //绘制边框
                                this.WmBorderPaint(this, nc_arg);

                                //把画布图片绑定到分层窗体上
                                IntPtr hdcDst = GetDC(this.Handle);
                                IntPtr hdcSrc = CreateCompatibleDC(hdcDst);

                                IntPtr newBitmap = bmp.GetHbitmap(Color.FromArgb(0));//创建一张位图
                                IntPtr oldBitmap = SelectObject(hdcSrc, newBitmap);//位图绑定到DC设备上

                                Point pptDst = new Point(this.Bounds.Left, this.Bounds.Top);
                                Size psize = new Size(bmp.Width, bmp.Height);
                                Point pptSrc = new Point(0, 0);

                                BLENDFUNCTION pblend = new BLENDFUNCTION();
                                pblend.BlendOp = AC_SRC_OVER;
                                pblend.SourceConstantAlpha = 255;
                                pblend.AlphaFormat = AC_SRC_ALPHA;
                                pblend.BlendFlags = 0;

                                UpdateLayeredWindow(this.Handle, hdcDst, ref pptDst, ref psize, hdcSrc, ref pptSrc, 0, ref pblend, ULW_ALPHA);

                                SelectObject(hdcSrc, oldBitmap);
                                ReleaseDC(this.Handle, hdcDst);
                                DeleteObject(newBitmap);
                                DeleteDC(hdcSrc);


                                bmp.Dispose();
                                g.Dispose();
                            }

                            break;
                        }
                    default:
                        {
                            this.DefWndProc(ref m);
                            break;
                        }
                }
            }

            protected virtual void Dispose(bool disposing)
            {
                if (disposing)
                {
                    this.HookListenStop();
                    if (this.shadow_image_tmp != null)
                    {
                        this.shadow_image_tmp.Dispose();
                        this.shadow_image_tmp = null;
                    }
                    //清理托管资源
                }
                this.DestroyHandle();
                //清理非托管资源
            }

            #endregion

            #region  公开方法

            /// <summary>
            /// 显示下拉列表弹层(同时安装钩子)
            /// </summary>
            public void Show()
            {
                if (this.owner == null)
                    return;

                this.wndproc_mousepressed = false;
                this.wndproc_ismousein = false;


                TBPadding scale_itemTBPadding = new TBPadding((int)Math.Ceiling(this.owner.Picker.Item.TBPadding.Top * this.owner.ScaleDpi), (int)Math.Ceiling(this.owner.Picker.Item.TBPadding.Bottom * this.owner.ScaleDpi));
                NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.owner.Font);
                this.item_height = scale_itemTBPadding.Top + font_metrics.GetFontRealHeight() + scale_itemTBPadding.Bottom;

                Rectangle bounds = this.AdjustBounds();
                if (this.shadow_image_tmp != null)
                {
                    this.shadow_image_tmp.Dispose();
                }
                this.shadow_image_tmp = this.CreateShadowBitmap(bounds.Width, bounds.Height);

                NativeMethods.SetWindowPos(this.Handle, IntPtr.Zero, bounds.X, bounds.Y, bounds.Width, bounds.Height, SWP_NOACTIVATE | SWP_SHOWWINDOW);

                this.SetScrollOffsetY(0);
                this.Invalidate();

                this.HookListenStart();
            }

            /// <summary>
            /// 隐藏下拉列表弹层(同时取消钩子)
            /// </summary>
            public void Hide()
            {
                this.HideView();
                this.HookListenStop();
            }

            /// <summary>
            /// 绘制下拉列表弹层
            /// </summary>
            public void Invalidate()
            {
                NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_PAINT, (IntPtr)0, (IntPtr)0);
            }

            /// <summary>
            /// 设置滚动条滚动条拇指Y轴距离
            /// </summary>
            /// <param name="y"></param>
            public void SetScrollOffsetY(int y)
            {
                if (!this.ScrollVisible)
                {
                    if (this.scrollOffsetY != 0)
                    {
                        this.scrollOffsetY = 0;
                        this.AdjustScrollRectangle();
                        this.Invalidate();
                    }
                    return;
                }

                int itemsRealityHeight = this.GetItemsRealityHeight();

                int new_y = y;
                if (new_y < this.ClientRectangle.Height - itemsRealityHeight)
                {
                    new_y = this.ClientRectangle.Height - itemsRealityHeight;
                }
                if (new_y > 0)
                {
                    new_y = 0;
                }

                int old_y = this.scrollOffsetY;
                this.scrollOffsetY = new_y;
                this.AdjustScrollRectangle();

                if (old_y != new_y)
                {
                    this.Invalidate();
                }
            }

            /// <summary>
            /// 将指定屏幕点的位置计算成工作区坐标
            /// </summary>
            /// <param name="point"></param>
            /// <returns></returns>
            public Point PointToClient(Point point)
            {
                Rectangle bounds = this.Bounds;
                return new Point(point.X - (bounds.X + this.ClientBounds.X), point.Y - (bounds.Y + this.ClientBounds.Y));
            }

            /// <summary>
            /// 将指定工作区点的位置计算成屏幕坐标
            /// </summary>
            /// <param name="point"></param>
            /// <returns></returns>
            public Point PointToScreen(Point point)
            {
                Rectangle bounds = this.Bounds;
                return new Point((bounds.X + this.ClientBounds.X) + point.X, (bounds.Y + this.ClientBounds.Y) + point.Y);
            }

            /// <summary>
            /// 鼠标是否进入选项
            /// </summary>
            /// <param name="index">选项索引</param>
            /// <returns></returns>
            internal bool IsMouseEnter(int index)
            {
                return (index != -1 && this.mousedownindex == index);
            }

            /// <summary>
            /// 显式调用
            /// </summary>
            public void Dispose()
            {
                Dispose(true);//释放托管和非托管资源
                System.GC.SuppressFinalize(this);//阻止GC调用析构函数
            }

            #endregion

            #region 私有方法

            /// <summary>
            /// 计算下拉列表弹层显示区域Bounds
            /// </summary>
            private Rectangle AdjustBounds()
            {
                if (this.owner == null)
                    return Rectangle.Empty;

                Rectangle screen_rect = Screen.GetWorkingArea(this.owner);
                Rectangle owner_bounds = new Rectangle(this.owner.PointToScreen(new Point(0, 0)), new Size(this.owner.Size.Width, this.owner.GetSingleRowHeight()));
                int scale_roundedCorner = (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi);
                int scale_nativeWindow_client_width = owner_bounds.Width;
                int scale_nativeWindow_client_height = this.GetItemsRealityHeight();
                if (this.owner.Picker.MaxHeight > 0)
                {
                    scale_nativeWindow_client_height = Math.Min(scale_nativeWindow_client_height, (int)Math.Ceiling(this.owner.Picker.MaxHeight * this.owner.ScaleDpi));
                }

                int nativeWindow_y = owner_bounds.Bottom;//下拉框Top默认位置
                if (nativeWindow_y + scale_roundedCorner + scale_nativeWindow_client_height + scale_roundedCorner > screen_rect.Bottom)//下拉框高度超过屏幕底部
                {
                    if (owner_bounds.Y > screen_rect.Height * 3 / 4)//下拉框Top默认位置在屏幕高度3/4下面
                    {
                        if (owner_bounds.Y - scale_roundedCorner - scale_nativeWindow_client_height - scale_roundedCorner - 10 < 0)
                        {
                            scale_nativeWindow_client_height = owner_bounds.Y - scale_roundedCorner - scale_roundedCorner - 10;//下拉框高度不能超过屏幕顶部
                            if (this.owner.Picker.MaxHeight > 0)
                            {
                                scale_nativeWindow_client_height = Math.Min(scale_nativeWindow_client_height, (int)Math.Ceiling(this.owner.Picker.MaxHeight * this.owner.ScaleDpi));
                            }
                        }
                        nativeWindow_y = owner_bounds.Y - scale_roundedCorner - scale_nativeWindow_client_height - scale_roundedCorner;//下拉框改为Bottom默认位置
                    }
                    else
                    {
                        scale_nativeWindow_client_height = screen_rect.Bottom - nativeWindow_y - scale_roundedCorner - scale_roundedCorner;//下拉框高度不能超过屏幕底部
                        if (this.owner.Picker.MaxHeight > 0)
                        {
                            scale_nativeWindow_client_height = Math.Min(scale_nativeWindow_client_height, (int)Math.Ceiling(this.owner.Picker.MaxHeight * this.owner.ScaleDpi));
                        }
                    }
                }

                return new Rectangle(owner_bounds.X - scale_roundedCorner, nativeWindow_y, scale_roundedCorner + scale_nativeWindow_client_width + scale_roundedCorner, scale_roundedCorner + scale_nativeWindow_client_height + scale_roundedCorner);

            }

            /// <summary>
            /// 更新下拉列表弹层滚动条Rect
            /// </summary>
            private void AdjustScrollRectangle()
            {
                int itemsRealityHeight = this.GetItemsRealityHeight();
                int scale_roundedCorner = (int)Math.Ceiling(this.owner.Picker.RoundSize * owner.ScaleDpi);
                int scale_scrollThickness = this.ScrollVisible ? (int)Math.Ceiling(owner.Picker.ScrollBar.TrackThickness * owner.ScaleDpi) : 0;
                int scale_scrollSlideMinSize = (int)Math.Ceiling(this.owner.Picker.ScrollBar.ThumbMinSize * owner.ScaleDpi);

                this.scrollTrackRect = new Rectangle(this.ClientRectangle.Right - scale_scrollThickness, this.ClientRectangle.Y + scale_roundedCorner, scale_scrollThickness, this.ClientRectangle.Height - scale_roundedCorner * 2);

                int slide_height = (int)Math.Max(Math.Min(this.scrollTrackRect.Height, scale_scrollSlideMinSize), this.scrollTrackRect.Height * ((float)this.ClientRectangle.Height / (float)itemsRealityHeight));
                int slide_y = (int)(this.scrollTrackRect.Y + (this.scrollTrackRect.Height - slide_height) * (-this.scrollOffsetY / (float)(itemsRealityHeight - this.ClientRectangle.Height)));
                this.scrollThumbRect = new Rectangle(this.ClientRectangle.Right - scale_scrollThickness, slide_y, scale_scrollThickness, slide_height);
            }

            /// <summary>
            /// 获取列表真实高度
            /// </summary>
            /// <returns></returns>
            private int GetItemsRealityHeight()
            {
                return ((this.owner == null || this.owner.ItemsSource.Count == 0) ? 1 : this.owner.ItemsSource.Count) * this.item_height;
            }

            /// <summary>
            /// 获取进入工作区的第一个选项索引
            /// </summary>
            /// <returns></returns>
            private int GetClientRectangleFirstIndex()
            {
                if (-this.scrollOffsetY < this.item_height)
                    return 0;
                else
                    return -this.scrollOffsetY / this.item_height;
            }

            /// <summary>
            /// 根据坐标查找选项索引
            /// </summary>
            /// <param name="point">相对于控件模拟工作区坐标</param>
            /// <returns></returns>
            private int FindItemIndexForPoint(Point point)
            {
                if (this.owner.ItemsSource.Count == 0 || !this.ClientRectangle.Contains(point))
                    return -1;

                if (this.ScrollVisible && this.scrollTrackRect.Contains(point))
                    return -1;

                point.Y += -this.scrollOffsetY;

                return (int)Math.Ceiling(point.Y / (float)this.item_height) - 1;

            }

            /// <summary>
            /// 隐藏窗体（只隐藏不作任何其他处理）
            /// </summary>
            internal void HideView()
            {
                this.wndproc_mousepressed = false;
                this.wndproc_ismousein = false;
                NativeMethods.SetWindowPos(this.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
                this.SelectedItems.Clear();
            }

            /// <summary>
            /// 创建带阴影边框图片
            /// </summary>
            /// <param name="width"></param>
            /// <param name="height"></param>
            /// <returns></returns>
            private Bitmap CreateShadowBitmap(int width, int height)
            {
                Color shadow_color = this.owner.StyleAppearance.Picker.ShadowColor;
                int roundedCorner = (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi);
                int shadowSize = roundedCorner * 2;

                Bitmap bmp = new Bitmap(width, height);

                //上
                for (int x = shadowSize; x < width - shadowSize; x++)
                {
                    for (int y = 0; y < shadowSize; y++)
                    {
                        int proportion = (int)(255 * Math.Min(1, EaseBothCore((shadowSize - y) / (double)shadowSize, 2)));
                        Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                        bmp.SetPixel(x, shadowSize - y, nColor);
                    }
                }
                ////下
                for (int x = shadowSize; x < width - shadowSize; x++)
                {
                    for (int y = 0; y < shadowSize; y++)
                    {
                        int proportion = (int)(255 * Math.Min(1, EaseInCore((shadowSize - y) / (double)shadowSize, 2)));
                        Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                        bmp.SetPixel(x, height - shadowSize + y, nColor);
                    }
                }
                //左
                for (int y = shadowSize; y < height - shadowSize; y++)
                {
                    for (int x = 0; x < shadowSize; x++)
                    {
                        int proportion = (int)(255 * Math.Min(1, EaseBothCore((shadowSize - x) / (double)shadowSize, 2)));
                        Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                        bmp.SetPixel(shadowSize - x, y, nColor);
                    }
                }
                //右
                for (int y = shadowSize; y < height - shadowSize; y++)
                {
                    for (int x = 0; x < shadowSize; x++)
                    {
                        int proportion = (int)(255 * Math.Min(1, EaseBothCore((shadowSize - x) / (double)shadowSize, 2)));
                        Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                        bmp.SetPixel(width - shadowSize + x, y, nColor);
                    }
                }
                //左上
                {
                    Point center = new Point(shadowSize, shadowSize);
                    for (int x = shadowSize; x >= 0; x--)
                    {
                        for (int y = shadowSize; y >= 0; y--)
                        {
                            int tmp = (int)Math.Sqrt(Math.Pow(x - center.X, 2) + Math.Pow(y - center.Y, 2));
                            if (tmp <= shadowSize)
                            {
                                int proportion = (int)(255 * EaseBothCore((shadowSize - tmp) / (double)shadowSize, 2));
                                Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                                bmp.SetPixel(x, y, nColor);
                            }
                        }
                    }
                }
                //右上
                {
                    Point center = new Point(width - shadowSize, shadowSize);
                    for (int x = width - shadowSize; x < width; x++)
                    {
                        for (int y = shadowSize; y >= 0; y--)
                        {
                            int tmp = (int)Math.Sqrt(Math.Pow(x - center.X, 2) + Math.Pow(y - center.Y, 2));
                            if (tmp <= shadowSize)
                            {
                                int proportion = (int)(255 * EaseBothCore((shadowSize - tmp) / (double)shadowSize, 2));
                                Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                                bmp.SetPixel(x, y, nColor);
                            }
                        }
                    }
                }
                //右下
                {
                    Point center = new Point(width - shadowSize, height - shadowSize);
                    for (int x = width - shadowSize; x < width; x++)
                    {
                        for (int y = height - shadowSize; y < height; y++)
                        {
                            int tmp = (int)Math.Sqrt(Math.Pow(x - center.X, 2) + Math.Pow(y - center.Y, 2));
                            if (tmp <= shadowSize)
                            {
                                int proportion = (int)(255 * EaseInCore((shadowSize - tmp) / (double)shadowSize, 2));
                                Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                                bmp.SetPixel(x, y, nColor);
                            }
                        }
                    }
                }
                //左下
                {
                    Point center = new Point(shadowSize, height - shadowSize);
                    for (int x = shadowSize; x >= 0; x--)
                    {
                        for (int y = height - shadowSize; y < height; y++)
                        {
                            int tmp = (int)Math.Sqrt(Math.Pow(x - center.X, 2) + Math.Pow(y - center.Y, 2));
                            if (tmp <= shadowSize)
                            {
                                int proportion = (int)(255 * EaseInCore((shadowSize - tmp) / (double)shadowSize, 2));
                                Color nColor = Color.FromArgb(proportion, shadow_color.R, shadow_color.G, shadow_color.B);
                                bmp.SetPixel(x, y, nColor);
                            }
                        }
                    }
                }

                return bmp;
            }

            /// <summary>
            /// EaseIn动画函数
            /// </summary>
            /// <param name="progress">进度百分值</param>
            /// <param name="power">曲线幂</param>
            /// <returns></returns>
            private double EaseInCore(double progress, double power)
            {
                power = Math.Max(0.0, power);
                return Math.Pow(progress, power);
            }

            /// <summary>
            /// EaseBoth动画函数
            /// </summary>
            /// <param name="progress">进度百分值</param>
            /// <param name="power">曲线幂</param>
            /// <returns></returns>
            private double EaseBothCore(double progress, double power)
            {
                if (progress >= 0.5)
                    return (1.0 - EaseInCore((1.0 - progress) * 2.0, power)) * 0.5 + 0.5;
                return EaseInCore(progress * 2.0, power) * 0.5;
            }

            /// <summary>
            /// 开始监听钩子
            /// </summary>
            private void HookListenStart()
            {
                if (hook_owner != this)
                {
                    if (this.hook_id != 0)
                    {
                        if (!UnhookWindowsHookEx(this.hook_id))
                        {
                            throw new Exception("DropDownListPlusNativeWindow 取消鼠标钩子失败");
                        }

                        hook_id_array.Remove(this.hook_id);
                        this.hook_id = 0;

                        Debug.Print("取消 mousehook handle:" + this.Handle.ToString() + " hook_id:" + this.hook_id.ToString() + " visible:" + this.Visible.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));
                    }
                    if (hook_owner != null)
                    {
                        hook_owner.HideView();
                    }
                }

                if (this.hook_id == 0)
                {
                    if (this.hook_callback == null)
                    {
                        this.hook_callback = new HookProc(this.MouseHookProc);
                    }
                    this.hook_id = SetWindowsHookEx(WH_MOUSE, this.hook_callback, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
                    if (this.hook_id == 0)
                    {
                        throw new Exception("DropDownListPlusNativeWindow 安装鼠标钩子失败");
                    }
                    else
                    {
                        Debug.Print("安装 mousehook handle:" + this.Handle.ToString() + " hook_id:" + this.hook_id.ToString() + " visible:" + this.Visible.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                        hook_id_array.Add(this.hook_id);
                        hook_owner = this;
                    }
                }
            }
            /// <summary>  
            /// 结束监听钩子  
            /// </summary>  
            private void HookListenStop()
            {
                if (hook_owner == this)
                {
                    hook_owner = null;
                    if (this.hook_id != 0)
                    {
                        if (!UnhookWindowsHookEx(this.hook_id))
                        {
                            throw new Exception("DropDownListPlusNativeWindow 取消鼠标钩子失败");
                        }
                        hook_id_array.Remove(this.hook_id);
                        this.hook_id = 0;

                        Debug.Print("取消 mousehook handle:" + this.Handle.ToString() + " hook_id:" + this.hook_id.ToString() + " visible:" + this.Visible.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));
                    }
                }
            }
            /// <summary>
            /// 利用钩子处理鼠标事件
            /// </summary>
            /// <param name="nCode"></param>
            /// <param name="wParam"></param>
            /// <param name="lParam"></param>
            /// <returns></returns>
            private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
            {
                Debug.Print("mousehook handle:" + this.Handle.ToString() + " hook_id:" + this.hook_id.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                switch (unchecked((int)(long)wParam))
                {
                    //关闭下拉列表弹层
                    case WM_RBUTTONDOWN:
                    case WM_MBUTTONDOWN:
                    case WM_NCLBUTTONDOWN:
                    case WM_NCRBUTTONDOWN:
                    case WM_NCMBUTTONDOWN:
                        {
                            // Point client_point = this.PointToClient(this.GetMouseHookStructMousePosition(lParam));
                            Point client_point = this.PointToClient(Control.MousePosition);
                            if (!this.ClientRectangle.Contains(client_point) && this.Visible)
                            {
                                this.wndproc_mousepressed = false;
                                this.wndproc_ismousein = false;
                                NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_CLOSED, (IntPtr)0, (IntPtr)0);
                            }
                            break;
                        }
                    //关闭下拉列表弹层、鼠标按下
                    case WM_LBUTTONDOWN:
                        {
                            // Point client_point = this.PointToClient(this.GetMouseHookStructMousePosition(lParam));
                            Point client_point = this.PointToClient(Control.MousePosition);
                            if (!this.ClientRectangle.Contains(client_point))
                            {
                                if (this.Visible)
                                {
                                    if (this.owner.Parent != null && new Rectangle(this.owner.Parent.PointToScreen(this.owner.Bounds.Location), this.owner.Bounds.Size).Contains(Control.MousePosition))
                                    {
                                        this.owner.isControlSelfClosing = true;
                                    }

                                    this.wndproc_mousepressed = false;
                                    this.wndproc_ismousein = false;
                                    NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_CLOSED, (IntPtr)0, (IntPtr)0);
                                }
                            }
                            else
                            {
                                this.wndproc_mousepressed = true;
                                this.wndproc_ismousein = true;
                                NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEDOWN, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                            }
                            break;
                        }
                    //鼠标按下释放、鼠标离开失焦
                    case WM_LBUTTONUP:
                        {
                            if (this.wndproc_mousepressed)
                            {
                                // Point client_point = this.PointToClient(this.GetMouseHookStructMousePosition(lParam));
                                Point client_point = this.PointToClient(Control.MousePosition);
                                this.wndproc_mousepressed = false;
                                NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEUP, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                                if (!this.ClientRectangle.Contains(client_point))
                                {
                                    this.wndproc_ismousein = false;
                                    NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSELEAVE, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                                }
                            }
                            break;
                        }
                    //鼠标进入、鼠标移动、鼠标离开失焦
                    case WM_MOUSEMOVE:
                        {
                            // Point client_point = this.PointToClient(this.GetMouseHookStructMousePosition(lParam));
                            Point client_point = this.PointToClient(Control.MousePosition);
                            if (this.wndproc_mousepressed)
                            {
                                NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEMOVE, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                            }
                            else
                            {
                                if (this.wndproc_ismousein)
                                {
                                    if (!this.ClientRectangle.Contains(client_point))
                                    {
                                        this.wndproc_ismousein = false;
                                        NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSELEAVE, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                                    }
                                    else
                                    {
                                        NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEMOVE, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                                    }
                                }
                                else
                                {
                                    if (this.ClientRectangle.Contains(client_point))
                                    {
                                        this.wndproc_ismousein = true;
                                        NativeMethods.SendMessage(this.Handle, NativeMethods.WM_USER_DROPDROWLISTPLUS_MOUSEENTER, (IntPtr)0, NativeMethods.MAKELPARAM(client_point.X, client_point.Y));
                                    }
                                }
                            }
                        }
                        break;
                }

                return CallNextHookEx(this.hook_id, nCode, wParam, lParam);
            }
            /// <summary>
            /// 获取控件鼠标钩子鼠标坐标(相对于屏幕)
            /// </summary>
            /// <returns></returns>
            private Point GetMouseHookStructMousePosition(IntPtr lParam)
            {
                MouseHookStruct mhs = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
                return new Point(mhs.pt.X, mhs.pt.Y);
            }

            /// <summary>
            /// 鼠标进入
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmMouseEnter(object sender, MouseEventArgs e)
            {
                Debug.Print("MouseEnter " + e.Location.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                this.WmMouseMove(sender, e);
            }
            /// <summary>
            /// 鼠标离开
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmMouseLeave(object sender, MouseEventArgs e)
            {
                Debug.Print("MouseLeave " + e.Location.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                this.mousedownindex = -1;
                this.mouseenterindex = -1;
                this.Invalidate();
            }
            /// <summary>
            /// 鼠标按下
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmMouseDown(object sender, MouseEventArgs e)
            {
                Debug.Print("MouseDown " + e.Location.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                if (this.ScrollVisible && this.scrollTrackRect.Contains(e.Location))
                {
                    if (this.scrollThumbRect.Contains(e.Location))
                    {
                        this.mousedownindex = -2;
                        this.mousedownpoint = e.Location;
                        this.mousedown_scrollOffsetY = this.scrollOffsetY;
                    }
                    else
                    {
                        this.mousedownindex = -1;
                    }
                }
                else
                {
                    this.mousedownindex = this.FindItemIndexForPoint(e.Location);
                }

            }
            /// <summary>
            /// 鼠标释放
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmMouseUp(object sender, MouseEventArgs e)
            {
                Debug.Print("MouseUp " + e.Location.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                if (this.mousedownindex >= 0)
                {
                    int index = this.FindItemIndexForPoint(e.Location);
                    if (index != -1 && this.mousedownindex == index)
                    {
                        DropDownListPlusItem item = this.owner.ItemsSource[index];
                        if (item.Enabled)
                        {
                            if (this.owner.Multiple)
                            {
                                int selected_index = this.SelectedItems.IndexOf(item);
                                if (selected_index > -1)
                                {
                                    this.SelectedItems.Remove(item);
                                }
                                else
                                {
                                    this.SelectedItems.Add(item);
                                }
                            }
                            else
                            {
                                this.SelectedItems = new List<DropDownListPlusItem>() { this.owner.ItemsSource[index] };
                                this.owner.HideNativeWindow();
                            }
                            this.Invalidate();
                        }
                    }
                }
                this.mousedownindex = -1;

            }
            /// <summary>
            /// 鼠标移动
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmMouseMove(object sender, MouseEventArgs e)
            {
                Debug.Print("MouseMove " + e.Location.ToString() + " " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                if (this.mousedownindex != -1)
                {
                    if (this.mousedownindex == -2)//拖动滚动条
                    {
                        int itemsRealityHeight = this.GetItemsRealityHeight();

                        int new_y = this.mousedown_scrollOffsetY - (int)((itemsRealityHeight - this.ClientRectangle.Height) * (e.Location.Y - this.mousedownpoint.Y) / (float)(this.scrollTrackRect.Height - this.scrollThumbRect.Height));
                        this.SetScrollOffsetY(new_y);
                    }
                }
                else
                {
                    int index = this.FindItemIndexForPoint(e.Location);
                    if (this.mouseenterindex != index)
                    {
                        this.mouseenterindex = index;
                        this.Invalidate();
                    }
                }

            }
            /// <summary>
            /// 鼠标滚轮滚动
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmMouseWheel(object sender, MouseEventArgs e)
            {
                int offset = this.scrollOffsetY + (e.Delta / 120 * this.item_height / 2);
                this.SetScrollOffsetY(offset);
            }
            /// <summary>
            /// 下拉列表弹层关闭
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmClosed(object sender, EventArgs e)
            {
                Debug.Print("Closed " + DateTime.Now.ToString("时间[ HH:mm:ss fff ]"));

                if (this.owner != null)
                {
                    this.owner.HideNativeWindow();
                }
                else
                {
                    this.Hide();
                }
            }
            /// <summary>
            /// 绘制（模仿非工作区）
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmNCPaint(object sender, PaintEventArgs e)
            {
                //阴影
                e.Graphics.DrawImageUnscaled(this.shadow_image_tmp, new Point(0, 0));
            }
            /// <summary>
            /// 绘制（模仿工作区）
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmPaint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.owner.Font);
                LRPadding scale_client_LRPadding = new LRPadding((int)Math.Ceiling(this.owner.Picker.Item.LRPadding.Left * this.owner.ScaleDpi), (int)Math.Ceiling(this.owner.Picker.Item.LRPadding.Right * this.owner.ScaleDpi));
                Size scale_itemImageSize = new Size((int)Math.Ceiling(this.owner.Picker.Item.Icon.Size.Width * this.owner.ScaleDpi), (int)Math.Ceiling(this.owner.Picker.Item.Icon.Size.Height * this.owner.ScaleDpi));
                LRMargin scale_itemImageLRMargin = new LRMargin((int)Math.Ceiling(this.owner.Picker.Item.Icon.LRMargin.Left * this.owner.ScaleDpi), (int)Math.Ceiling(this.owner.Picker.Item.Icon.LRMargin.Right * this.owner.ScaleDpi));
                int scale_scrollThickness = (int)(this.owner.Picker.ScrollBar.TrackThickness * this.owner.ScaleDpi);
                int item_start_index = this.GetClientRectangleFirstIndex();

                // 背景
                SolidBrush back_sb = new SolidBrush(this.owner.ItemsSource.Count == 0 ? this.owner.StyleAppearance.Picker.NullTipBackColor : this.owner.StyleAppearance.Picker.BackColor);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.FillRectangle(back_sb, this.ClientRectangle);
                g.SmoothingMode = SmoothingMode.Default;
                back_sb.Dispose();

                //选项
                {
                    Pen item_splitter_pen = null;
                    LinearGradientBrush item_splitter_lgb = null;
                    if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.StraightLine)
                    {
                        item_splitter_pen = new Pen(this.owner.StyleAppearance.Picker.SplitterColor, 1);
                    }
                    else if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.VerticalLine)
                    {
                        item_splitter_pen = new Pen(this.owner.StyleAppearance.Picker.Item.Selected.BackColor, font_metrics.GetFontStereotypesMargim()) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                    }
                    else if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.GradualLine)
                    {
                        item_splitter_lgb = new LinearGradientBrush(new PointF(this.ClientRectangle.X, this.ClientRectangle.Y), new PointF(this.ClientRectangle.Right, this.ClientRectangle.Y), Color.Transparent, Color.Transparent);
                        ColorBlend item_border_cb = new ColorBlend();
                        item_border_cb.Colors = new Color[] { Color.Transparent, this.owner.StyleAppearance.Picker.SplitterColor, this.owner.StyleAppearance.Picker.SplitterColor, Color.Transparent };
                        item_border_cb.Positions = new float[] { 0.0f, 0.23f, 0.70f, 1.0f };
                        item_splitter_lgb.InterpolationColors = item_border_cb;
                        item_splitter_pen = new Pen(item_splitter_lgb, 1);
                    }

                    SolidBrush commom_back_sb = new SolidBrush(Color.White);
                    SolidBrush commom_text_sb = new SolidBrush(Color.White);
                    Image commom_image = null;

                    for (int i = item_start_index; i < this.owner.ItemsSource.Count; i++)
                    {
                        DropDownListPlusItem item = this.owner.ItemsSource[i];
                        int top = this.ClientRectangle.Y + this.scrollOffsetY + i * this.item_height;
                        int bottom = top + this.item_height;
                        if (bottom >= this.ClientRectangle.Y)
                        {
                            if (top > this.ClientRectangle.Bottom)
                                break;

                            bool selected = this.SelectedItems.IndexOf(item) != -1;
                            bool ismouseenter = this.mouseenterindex == i;
                            Rectangle item_rect = new Rectangle(this.ClientRectangle.X, top, this.ClientRectangle.Width, this.item_height);
                            Rectangle item_image_rect = this.owner.Picker.Item.Icon.Visible ? new Rectangle(item_rect.X + scale_client_LRPadding.Left + scale_itemImageLRMargin.Left, item_rect.Y + (item_rect.Height - scale_itemImageSize.Height) / 2, scale_itemImageSize.Width, scale_itemImageSize.Height) : new Rectangle(item_rect.X, item_rect.Y + (item_rect.Height - scale_itemImageSize.Height) / 2, 0, scale_itemImageSize.Height);
                            Size item_text_size = new Size((int)Math.Ceiling(g.MeasureString(item.Text, this.owner.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                            int item_text_x = this.ClientRectangle.X + scale_client_LRPadding.Left + (this.owner.Picker.Item.Icon.Visible ? (scale_itemImageSize.Width + scale_itemImageLRMargin.Left + scale_itemImageLRMargin.Right) : font_metrics.GetFontStereotypesMargim()) + (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.VerticalLine ? font_metrics.GetFontStereotypesMargim() * 2 : 0);
                            int item_text_width = Math.Max(0, item_rect.Right - scale_client_LRPadding.Right - (this.ScrollVisible ? this.scrollTrackRect.Width : 0) - item_text_x);
                            Rectangle item_text_rect = new Rectangle(item_text_x, item_rect.Y + (item_rect.Height - item_text_size.Height) / 2, item_text_width, item_text_size.Height);

                            if (this.owner.Picker.Item.Icon.Visible)
                            {
                                commom_image = (item.Image != null) ? item.Image : this.owner.Picker.Item.Icon.Image;
                            }

                            if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.VerticalLine)
                            {
                                if (selected)
                                {
                                    commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Normal.BackColor;
                                    commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Enter.TextColor;
                                }
                                else
                                {
                                    if (item.Enabled == false)
                                    {
                                        commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Disabled.BackColor;
                                        commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Disabled.TextColor;
                                    }
                                    else
                                    {
                                        if (ismouseenter)
                                        {
                                            ismouseenter = true;
                                            commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Normal.BackColor;
                                            commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Enter.TextColor;
                                        }
                                        else
                                        {
                                            commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Normal.BackColor;
                                            commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Normal.TextColor;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (selected)
                                {
                                    commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Selected.BackColor;
                                    commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Selected.TextColor;
                                }
                                else
                                {
                                    if (item.Enabled == false)
                                    {
                                        commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Disabled.BackColor;
                                        commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Disabled.TextColor;
                                    }
                                    else
                                    {
                                        if (ismouseenter)
                                        {
                                            ismouseenter = true;
                                            commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Enter.BackColor;
                                            commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Enter.TextColor;
                                        }
                                        else
                                        {
                                            commom_back_sb.Color = this.owner.StyleAppearance.Picker.Item.Normal.BackColor;
                                            commom_text_sb.Color = this.owner.StyleAppearance.Picker.Item.Normal.TextColor;
                                        }
                                    }
                                }
                            }

                            DropDownListPlusItemDrawBeforeEventArgs before_arg = new DropDownListPlusItemDrawBeforeEventArgs(item, this.owner.ScaleDpi, g, item_rect, selected, ismouseenter, item_image_rect, item_text_rect, commom_back_sb, commom_text_sb, item_splitter_pen, false);
                            this.owner.OnItemDrawBefore(before_arg);

                            if (!before_arg.Cancel)
                            {
                                if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.Default)
                                {
                                    // 选项背景
                                    g.FillRectangle(commom_back_sb, item_rect);
                                    // 选项图片
                                    if (this.owner.Picker.Item.Icon.Visible && commom_image != null)
                                    {
                                        g.DrawImage(commom_image, item_image_rect);
                                    }
                                    // 选项文本
                                    g.DrawString(item.Text, this.owner.Font, commom_text_sb, item_text_rect.Location, StringFormat.GenericTypographic);
                                }
                                else if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.StraightLine || this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.GradualLine)
                                {
                                    // 选项背景
                                    g.FillRectangle(commom_back_sb, item_rect);
                                    // 选项图片
                                    if (this.owner.Picker.Item.Icon.Visible && commom_image != null)
                                    {
                                        g.DrawImage(commom_image, item_image_rect);
                                    }
                                    // 选项文本
                                    g.DrawString(item.Text, this.owner.Font, commom_text_sb, item_text_rect.Location, StringFormat.GenericTypographic);
                                    // 选项边框
                                    if (this.owner.Picker.StylePattern != DropDownListPlusPickerStylePattern.Default && i < this.owner.ItemsSource.Count - 1)
                                    {
                                        g.DrawLine(item_splitter_pen, item_rect.X, item_rect.Bottom - 1, item_rect.Right, item_rect.Bottom - 1);
                                    }
                                }
                                else if (this.owner.Picker.StylePattern == DropDownListPlusPickerStylePattern.VerticalLine)
                                {
                                    // 选项背景
                                    g.FillRectangle(commom_back_sb, item_rect);
                                    if (ismouseenter || selected)
                                    {
                                        g.SmoothingMode = SmoothingMode.AntiAlias;

                                        int item_selected_back_width = item_rect.Width - scale_client_LRPadding.Left - scale_client_LRPadding.Right - (this.ScrollVisible ? this.scrollTrackRect.Width : 0);
                                        item_rect = new Rectangle(item_rect.X + scale_client_LRPadding.Left, item_rect.Y, item_selected_back_width, item_rect.Height);
                                        GraphicsPath item_gp = ControlHelper.AdjustCircularPath(item_rect, (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi / 2));
                                        // 选中背景
                                        g.FillPath(commom_back_sb, item_gp);
                                        item_gp.Dispose();

                                        if (selected)
                                        {
                                            // 选中线
                                            g.DrawLine(item_splitter_pen, new Point(item_rect.X + (int)(item_splitter_pen.Width / 2), item_rect.Y + item_rect.Height / 4), new Point(item_rect.X + (int)(item_splitter_pen.Width / 2), item_rect.Bottom - item_rect.Height / 4));
                                        }

                                        g.SmoothingMode = SmoothingMode.Default;
                                    }


                                    // 选项图片
                                    if (this.owner.Picker.Item.Icon.Visible && commom_image != null)
                                    {
                                        g.DrawImage(commom_image, item_image_rect);
                                    }
                                    // 选项文本
                                    g.DrawString(item.Text, this.owner.Font, commom_text_sb, item_text_rect.Location, StringFormat.GenericTypographic);

                                }

                                DropDownListPlusItemDrawAfterEventArgs after_arg = new DropDownListPlusItemDrawAfterEventArgs(item, this.owner.ScaleDpi, g, item_rect, selected, ismouseenter, item_image_rect, item_text_rect, commom_back_sb, commom_text_sb, item_splitter_pen);
                                this.owner.OnItemDrawAfter(after_arg);
                            }

                        }
                    }

                    commom_back_sb.Dispose();
                    commom_text_sb.Dispose();
                    if (item_splitter_pen != null)
                        item_splitter_pen.Dispose();
                    if (item_splitter_lgb != null)
                        item_splitter_lgb.Dispose();

                }

                // 定位
                if (this.owner.Picker.LocateVisible && this.ScrollVisible)
                {
                    List<DropDownListPlusItem> selectedItems_tmp = this.owner.Multiple ? this.SelectedItems : this.owner.selectedItems;
                    if (selectedItems_tmp.Count > 0)
                    {
                        int locate_radius = (int)Math.Ceiling(3 * this.owner.ScaleDpi);
                        SolidBrush locate_sb = new SolidBrush(this.owner.StyleAppearance.Picker.LocateColor);
                        g.SmoothingMode = SmoothingMode.AntiAlias;

                        for (int i = 0; i < this.SelectedItems.Count; i++)
                        {
                            int index = this.owner.ItemsSource.IndexOf(selectedItems_tmp[i]);
                            int y = this.scrollTrackRect.Y + (int)(this.scrollTrackRect.Height * ((index) / (float)(this.owner.ItemsSource.Count - 1)) - locate_radius);
                            Rectangle locate_rect = new Rectangle(this.scrollTrackRect.X - locate_radius * 2, y, locate_radius * 2, locate_radius * 2);
                            g.FillEllipse(locate_sb, locate_rect);
                        }

                        g.SmoothingMode = SmoothingMode.Default;
                        locate_sb.Dispose();
                    }
                }

                // 滚动条
                if (this.ScrollVisible)
                {
                    SolidBrush bar_back_sb = new SolidBrush(this.owner.StyleAppearance.Picker.ScrollBar.TrackBackColor);
                    Pen slide_back_pen = new Pen(this.owner.StyleAppearance.Picker.ScrollBar.ThumbBackColor, scale_scrollThickness);

                    // 滚动条轨道
                    g.FillRectangle(bar_back_sb, this.scrollTrackRect);
                    // 滚动条拇指
                    PointF sp_start = new PointF(this.scrollThumbRect.X + scale_scrollThickness / 2, this.scrollThumbRect.Y);
                    PointF sp_end = new PointF(this.scrollThumbRect.X + scale_scrollThickness / 2, this.scrollThumbRect.Bottom);
                    g.DrawLine(slide_back_pen, sp_start, sp_end);

                    bar_back_sb.Dispose();
                    slide_back_pen.Dispose();
                }

                //空列表文本提示
                if (this.owner.ItemsSource.Count == 0)
                {
                    Size nullitemstiptext_size = new Size((int)Math.Ceiling(g.MeasureString(this.owner.Picker.NullTipText, this.owner.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                    SolidBrush nullitemstiptext_sb = new SolidBrush(this.owner.StyleAppearance.Picker.NullTipTextColor);
                    g.DrawString(this.owner.Picker.NullTipText, this.owner.Font, nullitemstiptext_sb, new RectangleF(this.ClientRectangle.X + (this.ClientRectangle.Width - nullitemstiptext_size.Width) / 2, this.ClientRectangle.Y + (this.ClientRectangle.Height - nullitemstiptext_size.Height) / 2, nullitemstiptext_size.Width, nullitemstiptext_size.Height), StringFormat.GenericTypographic);
                    nullitemstiptext_sb.Dispose();
                }



            }
            /// <summary>
            /// 绘制（边框）
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WmBorderPaint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;

                // 边框
                int scale_roundedCorner = (int)Math.Ceiling(this.owner.Picker.RoundSize * this.owner.ScaleDpi);
                GraphicsPath border_path = ControlHelper.AdjustCircularPath(this.ClientRectangle, scale_roundedCorner);
                Pen border_pen = new Pen(this.owner.StyleAppearance.Picker.BorderColor, 1);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.DrawPath(border_pen, border_path);
                g.SmoothingMode = SmoothingMode.Default;
                border_pen.Dispose();
                border_path.Dispose();
            }

            #endregion

            //GC调用的析构函数
            ~DropDownListPlusNativeWindow()
            {
                Dispose(false);//释放非托管资源
            }

        }

        /// <summary>
        /// DropDownListPlus选项临时信息对象
        /// </summary>
        private class DropDownListPlusItemInfo
        {
            /// <summary>
            /// 选项
            /// </summary>
            public DropDownListPlusItem item { get; set; }
            /// <summary>
            /// 选项文本Size
            /// </summary>
            public Size item_text_size { get; set; }
            /// <summary>
            /// 选项rect
            /// </summary>
            public Rectangle item_rect { get; set; }
            /// <summary>
            /// 选项图片rect
            /// </summary>
            public Rectangle item_image_rect { get; set; }
            /// <summary>
            /// 选项文本rect
            /// </summary>
            public Rectangle item_text_rect { get; set; }
            /// <summary>
            /// 选项删除按钮
            /// </summary>
            public Rectangle item_clearbutton_rect { get; set; }
        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinActivateColor = Color.Empty;
            private readonly Color defaultActivateColor = SystemColors.Window;
            private Color activateColor = Color.Empty;
            /// <summary>
            /// 控件激活的虚线框颜色
            /// </summary>
            [Description("控件激活的虚线框颜色")]
            [PropertyOrder(-200)]
            [SkinProperty(true, false)]
            public Color ActivateColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore())
                    {
                        return this.skinActivateColor;
                    }

                    if (this.activateColor != Color.Empty)
                    {
                        return this.activateColor;
                    }

                    return this.defaultActivateColor;
                }
                set
                {
                    if (this.activateColor == value)
                        return;

                    this.activateColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeActivateColor()
            {
                return this.activateColor != Color.Empty;
            }
            private void ResetActivateColor()
            {
                this.activateColor = Color.Empty;
                this.Invalidate();
            }

            private ItemAppearanceObject normal;
            /// <summary>
            /// 正常状态
            /// </summary>
            [Description("正常状态")]
            [PropertyOrder(-198)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public ItemAppearanceObject Normal
            {
                get
                {
                    if (this.normal == null)
                        this.normal = new ItemAppearanceObject(this.owner, this, SystemColors.ActiveCaption, SystemColors.GradientActiveCaption);
                    return this.normal;
                }
            }

            private ItemAppearanceObject disabled;
            /// <summary>
            /// 禁用状态
            /// </summary>
            [Description("禁用状态")]
            [PropertyOrder(-197)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public ItemAppearanceObject Disabled
            {
                get
                {
                    if (this.disabled == null)
                        this.disabled = new ItemAppearanceObject(this.owner, this, SystemColors.InactiveBorder, SystemColors.InactiveCaption);
                    return this.disabled;
                }
            }

            private ContentAppearanceObject content;
            /// <summary>
            /// 内容区
            /// </summary>
            [Description("内容区")]
            [PropertyOrder(-196)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public ContentAppearanceObject Content
            {
                get
                {
                    if (this.content == null)
                        this.content = new ContentAppearanceObject(this.owner, this);
                    return this.content;
                }
            }

            private ClearButtonAppearanceObject clearButton;
            /// <summary>
            /// 清除按钮
            /// </summary>
            [Description("清除按钮")]
            [PropertyOrder(-195)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public ClearButtonAppearanceObject ClearButton
            {
                get
                {
                    if (this.clearButton == null)
                        this.clearButton = new ClearButtonAppearanceObject(this.owner, this);
                    return this.clearButton;
                }
            }

            private DropDownButtonAppearanceObject dropDownButton;
            /// <summary>
            /// 下拉按钮
            /// </summary>
            [Description("下拉按钮")]
            [PropertyOrder(-194)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public DropDownButtonAppearanceObject DropDownButton
            {
                get
                {
                    if (this.dropDownButton == null)
                        this.dropDownButton = new DropDownButtonAppearanceObject(this.owner, this);
                    return this.dropDownButton;
                }
            }

            private PickerAppearanceObject picker;
            /// <summary>
            /// 下拉面板
            /// </summary>
            [Description("下拉面板")]
            [PropertyOrder(-192)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public PickerAppearanceObject Picker
            {
                get
                {
                    if (this.picker == null)
                        this.picker = new PickerAppearanceObject(this.owner, this);
                    return this.picker;
                }
            }

            #endregion

            public class ItemAppearanceObject : AppearanceObjectBase
            {
                internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color borderColor, Color backColor) : base(owner, parent)
                {
                    this.defaultBorderColor = borderColor;
                    this.defaultBackColor = backColor;
                }

                #region 属性

                private Color skinBorderColor = Color.Empty;
                private readonly Color defaultBorderColor = Color.Empty;
                private Color borderColor = Color.Empty;
                /// <summary>
                /// 边框颜色
                /// </summary>
                [Description("边框颜色")]
                [PropertyOrder(-159)]
                [SkinProperty(true, false)]
                public Color BorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBorderColor;
                        }

                        if (this.borderColor != Color.Empty)
                        {
                            return this.borderColor;
                        }

                        return this.defaultBorderColor;
                    }
                    set
                    {
                        if (this.borderColor == value)
                            return;

                        this.borderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBorderColor()
                {
                    return this.borderColor != Color.Empty;
                }
                private void ResetBorderColor()
                {
                    this.borderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinBackColor = Color.Empty;
                private readonly Color defaultBackColor = Color.Empty;
                private Color backColor = Color.Empty;
                /// <summary>
                /// 背景颜色
                /// </summary>
                [Description("背景颜色")]
                [PropertyOrder(-158)]
                [SkinProperty(true, false)]
                public Color BackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBackColor;
                        }

                        if (this.backColor != Color.Empty)
                        {
                            return this.backColor;
                        }

                        return this.defaultBackColor;
                    }
                    set
                    {
                        if (this.backColor != value)
                        {
                            this.backColor = value;
                            this.Invalidate();
                        }
                    }
                }
                private bool ShouldSerializeBackColor()
                {
                    return this.backColor != Color.Empty;
                }
                private void ResetBackColor()
                {
                    this.backColor = Color.Empty;
                    this.Invalidate();
                }

                #endregion

            }

            public class ClearButtonAppearanceObject : AppearanceObjectBase
            {
                internal ClearButtonAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private ItemAppearanceObject normal;
                /// <summary>
                /// 正常状态
                /// </summary>
                [Description("正常状态")]
                [PropertyOrder(-194)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Normal
                {
                    get
                    {
                        if (this.normal == null)
                            this.normal = new ItemAppearanceObject(this.owner, this, Color.Empty, SystemColors.Window);
                        return this.normal;
                    }
                }

                private ItemAppearanceObject enter;
                /// <summary>
                /// 鼠标进入状态
                /// </summary>
                [Description("鼠标进入状态")]
                [PropertyOrder(-192)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Enter
                {
                    get
                    {
                        if (this.enter == null)
                            this.enter = new ItemAppearanceObject(this.owner, this, SystemColors.GradientInactiveCaption, SystemColors.Window);
                        return this.enter;
                    }
                }

                private ItemAppearanceObject disabled;
                /// <summary>
                /// 禁用状态
                /// </summary>
                [Description("禁用状态")]
                [PropertyOrder(-190)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Disabled
                {
                    get
                    {
                        if (this.disabled == null)
                            this.disabled = new ItemAppearanceObject(this.owner, this, SystemColors.InactiveCaption, SystemColors.Window);
                        return this.disabled;
                    }
                }

                #endregion

                public class ItemAppearanceObject : AppearanceObjectBase
                {
                    internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color backColor, Color foreColor) : base(owner, parent)
                    {
                        this.defaultBackColor = backColor;
                        this.defaultForeColor = foreColor;
                    }

                    #region 属性

                    private Color skinBackColor = Color.Empty;
                    private readonly Color defaultBackColor = Color.Empty;
                    private Color backColor = Color.Empty;
                    /// <summary>
                    /// 背景颜色
                    /// </summary>
                    [Description("背景颜色")]
                    [PropertyOrder(-158)]
                    [SkinProperty(true, false)]
                    public Color BackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinBackColor;
                            }

                            if (this.backColor != Color.Empty)
                            {
                                return this.backColor;
                            }

                            return this.defaultBackColor;
                        }
                        set
                        {
                            if (this.backColor == value)
                                return;

                            this.backColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeBackColor()
                    {
                        return this.backColor != Color.Empty;
                    }
                    private void ResetBackColor()
                    {
                        this.backColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinForeColor = Color.Empty;
                    private Color defaultForeColor = Color.Empty;
                    private Color foreColor = Color.Empty;
                    /// <summary>
                    /// 前景颜色
                    /// </summary>
                    [Description("前景颜色")]
                    [PropertyOrder(-157)]
                    [SkinProperty(true, false)]
                    public Color ForeColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinForeColor;
                            }

                            if (this.foreColor != Color.Empty)
                            {
                                return this.foreColor;
                            }

                            return this.defaultForeColor;
                        }
                        set
                        {
                            if (this.foreColor == value)
                                return;

                            this.foreColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeForeColor()
                    {
                        return this.foreColor != Color.Empty;
                    }
                    private void ResetForeColor()
                    {
                        this.foreColor = Color.Empty;
                        this.Invalidate();
                    }

                    #endregion

                }

            }

            public class DropDownButtonAppearanceObject : AppearanceObjectBase
            {
                internal DropDownButtonAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private ItemAppearanceObject normal;
                /// <summary>
                /// 正常状态
                /// </summary>
                [Description("正常状态")]
                [PropertyOrder(-194)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Normal
                {
                    get
                    {
                        if (this.normal == null)
                            this.normal = new ItemAppearanceObject(this.owner, this, Color.Empty, SystemColors.Window);
                        return this.normal;
                    }
                }

                private ItemAppearanceObject enter;
                /// <summary>
                /// 鼠标进入状态
                /// </summary>
                [Description("鼠标进入状态")]
                [PropertyOrder(-192)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Enter
                {
                    get
                    {
                        if (this.enter == null)
                            this.enter = new ItemAppearanceObject(this.owner, this, SystemColors.GradientInactiveCaption, SystemColors.Window);
                        return this.enter;
                    }
                }

                private ItemAppearanceObject disabled;
                /// <summary>
                /// 禁用状态
                /// </summary>
                [Description("禁用状态")]
                [PropertyOrder(-190)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Disabled
                {
                    get
                    {
                        if (this.disabled == null)
                            this.disabled = new ItemAppearanceObject(this.owner, this, SystemColors.InactiveCaption, SystemColors.InactiveBorder);
                        return this.disabled;
                    }
                }

                #endregion

                public class ItemAppearanceObject : AppearanceObjectBase
                {
                    internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color backColor, Color foreColor) : base(owner, parent)
                    {
                        this.defaultBackColor = backColor;
                        this.defaultForeColor = foreColor;
                    }

                    #region 属性

                    private Color skinBackColor = Color.Empty;
                    private readonly Color defaultBackColor = Color.Empty;
                    private Color backColor = Color.Empty;
                    /// <summary>
                    /// 背景颜色
                    /// </summary>
                    [Description("背景颜色")]
                    [PropertyOrder(-158)]
                    [SkinProperty(true, false)]
                    public Color BackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinBackColor;
                            }

                            if (this.backColor != Color.Empty)
                            {
                                return this.backColor;
                            }

                            return this.defaultBackColor;
                        }
                        set
                        {
                            if (this.backColor == value)
                                return;

                            this.backColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeBackColor()
                    {
                        return this.backColor != Color.Empty;
                    }
                    private void ResetBackColor()
                    {
                        this.backColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinForeColor = Color.Empty;
                    private Color defaultForeColor = Color.Empty;
                    private Color foreColor = Color.Empty;
                    /// <summary>
                    /// 前景颜色
                    /// </summary>
                    [Description("前景颜色")]
                    [PropertyOrder(-157)]
                    [SkinProperty(true, false)]
                    public Color ForeColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinForeColor;
                            }

                            if (this.foreColor != Color.Empty)
                            {
                                return this.foreColor;
                            }

                            return this.defaultForeColor;
                        }
                        set
                        {
                            if (this.foreColor == value)
                                return;

                            this.foreColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeForeColor()
                    {
                        return this.foreColor != Color.Empty;
                    }
                    private void ResetForeColor()
                    {
                        this.foreColor = Color.Empty;
                        this.Invalidate();
                    }

                    #endregion

                }

            }

            public class ContentAppearanceObject : AppearanceObjectBase
            {
                internal ContentAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinNullTipTextColor = Color.Empty;
                private readonly Color defaultNullTipTextColor = SystemColors.Window;
                private Color nullTipTextColor = Color.Empty;
                /// <summary>
                /// 空值提示文本颜色
                /// </summary>
                [Description("空值提示文本颜色")]
                [PropertyOrder(-193)]
                [SkinProperty(true, false)]
                public Color NullTipTextColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinNullTipTextColor;
                        }

                        if (this.nullTipTextColor != Color.Empty)
                        {
                            return this.nullTipTextColor;
                        }

                        return this.defaultNullTipTextColor;
                    }
                    set
                    {
                        if (this.nullTipTextColor == value)
                            return;

                        this.nullTipTextColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeNullTipTextColor()
                {
                    return this.nullTipTextColor != Color.Empty;
                }
                private void ResetNullTipTextColor()
                {
                    this.nullTipTextColor = Color.Empty;
                    this.Invalidate();
                }

                private ItemObjectAppearanceObject item;
                /// <summary>
                /// 选项
                /// </summary>
                [Description("选项")]
                [PropertyOrder(-191)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemObjectAppearanceObject Item
                {
                    get
                    {
                        if (this.item == null)
                            this.item = new ItemObjectAppearanceObject(this.owner, this);
                        return this.item;
                    }
                }

                #endregion

                public class ItemObjectAppearanceObject : AppearanceObjectBase
                {
                    internal ItemObjectAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region 属性

                    private ItemAppearanceObject normal;
                    /// <summary>
                    /// 正常状态
                    /// </summary>
                    [Description("正常状态")]
                    [PropertyOrder(-194)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Normal
                    {
                        get
                        {
                            if (this.normal == null)
                                this.normal = new ItemAppearanceObject(this.owner, this, SystemColors.ActiveCaption, SystemColors.GradientInactiveCaption, SystemColors.Window, Color.Empty, SystemColors.ActiveCaption);
                            return this.normal;
                        }
                    }

                    private ItemAppearanceObject disabled;
                    /// <summary>
                    /// 禁用状态
                    /// </summary>
                    [Description("禁用状态")]
                    [PropertyOrder(-190)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Disabled
                    {
                        get
                        {
                            if (this.disabled == null)
                                this.disabled = new ItemAppearanceObject(this.owner, this, SystemColors.InactiveBorder, SystemColors.InactiveCaption, SystemColors.Window, Color.Empty, SystemColors.ActiveCaption);
                            return this.disabled;
                        }
                    }

                    #endregion

                    public class ItemAppearanceObject : AppearanceObjectBase
                    {
                        internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color borderColor, Color backColor, Color textColor, Color clearButtonBackColor, Color clearButtonForeColor) : base(owner, parent)
                        {
                            this.defaultBorderColor = borderColor;
                            this.defaultBackColor = backColor;
                            this.defaultTextColor = textColor;
                            this.defaultClearButtonBackColor = clearButtonBackColor;
                            this.defaultClearButtonForeColor = clearButtonForeColor;
                        }

                        #region 属性

                        private Color skinBorderColor = Color.Empty;
                        private readonly Color defaultBorderColor = Color.Empty;
                        private Color borderColor = Color.Empty;
                        /// <summary>
                        /// 边框颜色
                        /// </summary>
                        [Description("边框颜色")]
                        [PropertyOrder(-159)]
                        [SkinProperty(true, false)]
                        public Color BorderColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBorderColor;
                                }

                                if (this.borderColor != Color.Empty)
                                {
                                    return this.borderColor;
                                }

                                return this.defaultBorderColor;
                            }
                            set
                            {
                                if (this.borderColor == value)
                                    return;

                                this.borderColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBorderColor()
                        {
                            return this.borderColor != Color.Empty;
                        }
                        private void ResetBorderColor()
                        {
                            this.borderColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinBackColor = Color.Empty;
                        private readonly Color defaultBackColor = Color.Empty;
                        private Color backColor = Color.Empty;
                        /// <summary>
                        /// 背景颜色
                        /// </summary>
                        [Description("背景颜色")]
                        [PropertyOrder(-158)]
                        [SkinProperty(true, false)]
                        public Color BackColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBackColor;
                                }

                                if (this.backColor != Color.Empty)
                                {
                                    return this.backColor;
                                }

                                return this.defaultBackColor;
                            }
                            set
                            {
                                if (this.backColor == value)
                                    return;

                                this.backColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBackColor()
                        {
                            return this.backColor != Color.Empty;
                        }
                        private void ResetBackColor()
                        {
                            this.backColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinTextColor = Color.Empty;
                        private readonly Color defaultTextColor = Color.Empty;
                        private Color textColor = Color.Empty;
                        /// <summary>
                        /// 文本颜色
                        /// </summary>
                        [Description("文本颜色")]
                        [PropertyOrder(-157)]
                        [SkinProperty(true, false)]
                        public Color TextColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinTextColor;
                                }

                                if (this.textColor != Color.Empty)
                                {
                                    return this.textColor;
                                }

                                return this.defaultTextColor;
                            }
                            set
                            {
                                if (this.textColor == value)
                                    return;

                                this.textColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeTextColor()
                        {
                            return this.textColor != Color.Empty;
                        }
                        private void ResetTextColor()
                        {
                            this.textColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinClearButtonBackColor = Color.Empty;
                        private Color defaultClearButtonBackColor = Color.Empty;
                        private Color clearButtonBackColor = Color.Empty;
                        /// <summary>
                        /// 清除按钮背景颜色
                        /// </summary>
                        [Description("清除按钮背景颜色")]
                        [PropertyOrder(-155)]
                        [SkinProperty(true, false)]
                        public Color ClearButtonBackColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinClearButtonBackColor;
                                }

                                if (this.clearButtonBackColor != Color.Empty)
                                {
                                    return this.clearButtonBackColor;
                                }

                                return this.defaultClearButtonBackColor;
                            }
                            set
                            {
                                if (this.clearButtonBackColor == value)
                                    return;

                                this.clearButtonBackColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeClearButtonBackColor()
                        {
                            return this.clearButtonBackColor != Color.Empty;
                        }
                        private void ResetClearButtonBackColor()
                        {
                            this.clearButtonBackColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinClearButtonForeColor = Color.Empty;
                        private Color defaultClearButtonForeColor = Color.Empty;
                        private Color clearButtonForeColor = Color.Empty;
                        /// <summary>
                        /// 前景颜色
                        /// </summary>
                        [Description("前景颜色")]
                        [PropertyOrder(-153)]
                        [SkinProperty(true, false)]
                        public Color ClearButtonForeColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinClearButtonForeColor;
                                }

                                if (this.clearButtonForeColor != Color.Empty)
                                {
                                    return this.clearButtonForeColor;
                                }

                                return this.defaultClearButtonForeColor;
                            }
                            set
                            {
                                if (this.clearButtonForeColor == value)
                                    return;

                                this.clearButtonForeColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeClearButtonForeColor()
                        {
                            return this.clearButtonForeColor != Color.Empty;
                        }
                        private void ResetClearButtonForeColor()
                        {
                            this.clearButtonForeColor = Color.Empty;
                            this.Invalidate();
                        }

                        #endregion

                    }

                }

            }

            public class PickerAppearanceObject : AppearanceObjectBase
            {
                internal PickerAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinBorderColor = Color.Empty;
                private readonly Color defaultBorderColor = SystemColors.ActiveCaption;
                private Color borderColor = Color.Empty;
                /// <summary>
                /// 边框颜色
                /// </summary>
                [Description("边框颜色")]
                [PropertyOrder(-197)]
                [SkinProperty(true, false)]
                public Color BorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBorderColor;
                        }

                        if (this.borderColor != Color.Empty)
                        {
                            return this.borderColor;
                        }

                        return this.defaultBorderColor;
                    }
                    set
                    {
                        if (this.borderColor == value)
                            return;

                        this.borderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBorderColor()
                {
                    return this.borderColor != Color.Empty;
                }
                private void ResetBorderColor()
                {
                    this.borderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinBackColor = Color.Empty;
                private readonly Color defaultBackColor = SystemColors.Window;
                private Color backColor = Color.Empty;
                /// <summary>
                /// 背景颜色
                /// </summary>
                [Description("背景颜色")]
                [PropertyOrder(-195)]
                [SkinProperty(true, false)]
                public Color BackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBackColor;
                        }

                        if (this.backColor != Color.Empty)
                        {
                            return this.backColor;
                        }

                        return this.defaultBackColor;
                    }
                    set
                    {
                        if (this.backColor == value)
                            return;

                        this.backColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBackColor()
                {
                    return this.backColor != Color.Empty;
                }
                private void ResetBackColor()
                {
                    this.backColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinShadowColor = Color.Empty;
                private readonly Color defaultShadowColor = SystemColors.ButtonShadow;
                private Color shadowColor = Color.Empty;
                /// <summary>
                /// 阴影颜色
                /// </summary>
                [Description("阴影颜色")]
                [PropertyOrder(-193)]
                [SkinProperty(true, false)]
                public Color ShadowColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinShadowColor;
                        }

                        if (this.shadowColor != Color.Empty)
                        {
                            return this.shadowColor;
                        }

                        return this.defaultShadowColor;
                    }
                    set
                    {
                        if (this.shadowColor == value)
                            return;

                        this.shadowColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeShadowColor()
                {
                    return this.shadowColor != Color.Empty;
                }
                private void ResetShadowColor()
                {
                    this.shadowColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinSplitterColor = Color.Empty;
                private readonly Color defaultSplitterColor = SystemColors.ButtonFace;
                private Color splitterColor = Color.Empty;
                /// <summary>
                /// 选项分隔线颜色
                /// </summary>
                [Description(" 选项分隔线颜色")]
                [PropertyOrder(-192)]
                [SkinProperty(true, false)]
                public Color SplitterColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinSplitterColor;
                        }

                        if (this.splitterColor != Color.Empty)
                        {
                            return this.splitterColor;
                        }

                        return this.defaultSplitterColor;
                    }
                    set
                    {
                        if (this.splitterColor == value)
                            return;

                        this.splitterColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeSplitterColor()
                {
                    return this.splitterColor != Color.Empty;
                }
                private void ResetSplitterColor()
                {
                    this.splitterColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinLocateColor = Color.Empty;
                private readonly Color defaultLocateColor = Color.Gold;
                private Color locateColor = Color.Empty;
                /// <summary>
                /// 已选中选项定位颜色
                /// </summary>
                [Description("已选中选项定位颜色")]
                [PropertyOrder(-189)]
                [SkinProperty(true, false)]
                public Color LocateColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinLocateColor;
                        }

                        if (this.locateColor != Color.Empty)
                        {
                            return this.locateColor;
                        }

                        return this.defaultLocateColor;
                    }
                    set
                    {
                        if (this.locateColor == value)
                            return;

                        this.locateColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeLocateColor()
                {
                    return this.locateColor != Color.Empty;
                }
                private void ResetLocateColor()
                {
                    this.locateColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinNullTipBackColor = Color.Empty;
                private readonly Color defaultNullTipBackColor = SystemColors.Window;
                private Color nullTipBackColor = Color.Empty;
                /// <summary>
                /// 空数据源提示背景颜色
                /// </summary>
                [Description("空数据源提示背景颜色")]
                [PropertyOrder(-185)]
                [SkinProperty(true, false)]
                public Color NullTipBackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinNullTipBackColor;
                        }

                        if (this.nullTipBackColor != Color.Empty)
                        {
                            return this.nullTipBackColor;
                        }

                        return this.defaultNullTipBackColor;
                    }
                    set
                    {
                        if (this.nullTipBackColor == value)
                            return;

                        this.nullTipBackColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeNullTipBackColor()
                {
                    return this.nullTipBackColor != Color.Empty;
                }
                private void ResetNullTipBackColor()
                {
                    this.nullTipBackColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinNullTipTextColor = Color.Empty;
                private readonly Color defaultNullTipTextColor = Color.Tomato;
                private Color nullTipTextColor = Color.Empty;
                /// <summary>
                /// 空数据源提示文本颜色
                /// </summary>
                [Description("空数据源提示文本颜色")]
                [PropertyOrder(-184)]
                [SkinProperty(true, false)]
                public Color NullTipTextColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinNullTipTextColor;
                        }

                        if (this.nullTipTextColor != Color.Empty)
                        {
                            return this.nullTipTextColor;
                        }

                        return this.defaultNullTipTextColor;
                    }
                    set
                    {
                        if (this.nullTipTextColor == value)
                            return;

                        this.nullTipTextColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeNullTipTextColor()
                {
                    return this.nullTipTextColor != Color.Empty;
                }
                private void ResetNullTipTextColor()
                {
                    this.nullTipTextColor = Color.Empty;
                    this.Invalidate();
                }

                private ItemObjectAppearanceObject item;
                /// <summary>
                /// 选项
                /// </summary>
                [Description("选项")]
                [PropertyOrder(-180)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemObjectAppearanceObject Item
                {
                    get
                    {
                        if (this.item == null)
                            this.item = new ItemObjectAppearanceObject(this.owner, this);
                        return this.item;
                    }
                }

                private ScrollBarAppearanceObject scrollBar;
                /// <summary>
                /// 滚动条
                /// </summary>
                [Description("滚动条")]
                [PropertyOrder(-178)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ScrollBarAppearanceObject ScrollBar
                {
                    get
                    {
                        if (this.scrollBar == null)
                            this.scrollBar = new ScrollBarAppearanceObject(this.owner, this);
                        return this.scrollBar;
                    }
                }

                #endregion

                public class ItemObjectAppearanceObject : AppearanceObjectBase
                {
                    internal ItemObjectAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region 属性

                    private ItemAppearanceObject normal;
                    /// <summary>
                    /// 正常状态
                    /// </summary>
                    [Description("正常状态")]
                    [PropertyOrder(-194)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Normal
                    {
                        get
                        {
                            if (this.normal == null)
                                this.normal = new ItemAppearanceObject(this.owner, this, Color.Empty, SystemColors.ControlText);
                            return this.normal;
                        }
                    }

                    private ItemAppearanceObject enter;
                    /// <summary>
                    /// 鼠标进入状态
                    /// </summary>
                    [Description("鼠标进入状态")]
                    [PropertyOrder(-192)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Enter
                    {
                        get
                        {
                            if (this.enter == null)
                                this.enter = new ItemAppearanceObject(this.owner, this, SystemColors.GradientInactiveCaption, SystemColors.Window);
                            return this.enter;
                        }
                    }

                    private ItemAppearanceObject selected;
                    /// <summary>
                    /// 已选中状态
                    /// </summary>
                    [Description("已选中状态")]
                    [PropertyOrder(-191)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Selected
                    {
                        get
                        {
                            if (this.selected == null)
                                this.selected = new ItemAppearanceObject(this.owner, this, SystemColors.GradientActiveCaption, SystemColors.Window);
                            return this.selected;
                        }
                    }

                    private ItemAppearanceObject disabled;
                    /// <summary>
                    /// 禁用状态
                    /// </summary>
                    [Description("禁用状态")]
                    [PropertyOrder(-190)]
                    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                    [SkinProperty(true, false)]
                    public ItemAppearanceObject Disabled
                    {
                        get
                        {
                            if (this.disabled == null)
                                this.disabled = new ItemAppearanceObject(this.owner, this, SystemColors.InactiveCaption, SystemColors.ControlText);
                            return this.disabled;
                        }
                    }

                    #endregion

                    public class ItemAppearanceObject : AppearanceObjectBase
                    {
                        internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color backColor, Color textColor) : base(owner, parent)
                        {
                            this.defaultBackColor = backColor;
                            this.defaultTextColor = textColor;
                        }

                        #region 属性

                        private Color skinBackColor = Color.Empty;
                        private readonly Color defaultBackColor = Color.Empty;
                        private Color backColor = Color.Empty;
                        /// <summary>
                        /// 背景颜色
                        /// </summary>
                        [Description("背景颜色")]
                        [PropertyOrder(-158)]
                        [SkinProperty(true, false)]
                        public Color BackColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinBackColor;
                                }

                                if (this.backColor != Color.Empty)
                                {
                                    return this.backColor;
                                }

                                return this.defaultBackColor;
                            }
                            set
                            {
                                if (this.backColor == value)
                                    return;

                                this.backColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeBackColor()
                        {
                            return this.backColor != Color.Empty;
                        }
                        private void ResetBackColor()
                        {
                            this.backColor = Color.Empty;
                            this.Invalidate();
                        }

                        private Color skinTextColor = Color.Empty;
                        private readonly Color defaultTextColor = Color.Empty;
                        private Color textColor = Color.Empty;
                        /// <summary>
                        /// 文本颜色
                        /// </summary>
                        [Description("文本颜色")]
                        [PropertyOrder(-157)]
                        [SkinProperty(true, false)]
                        public Color TextColor
                        {
                            get
                            {
                                if (this.owner.GetSkinObjectSkinStateCore())
                                {
                                    return this.skinTextColor;
                                }

                                if (this.textColor != Color.Empty)
                                {
                                    return this.textColor;
                                }

                                return this.defaultTextColor;
                            }
                            set
                            {
                                if (this.textColor == value)
                                    return;

                                this.textColor = value;
                                this.Invalidate();
                            }
                        }
                        private bool ShouldSerializeTextColor()
                        {
                            return this.textColor != Color.Empty;
                        }
                        private void ResetTextColor()
                        {
                            this.textColor = Color.Empty;
                            this.Invalidate();
                        }

                        #endregion

                    }

                }

                public class ScrollBarAppearanceObject : AppearanceObjectBase
                {
                    internal ScrollBarAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                    #region 属性

                    private Color skinTrackBackColor = Color.Empty;
                    private readonly Color defaultTrackBackColor = SystemColors.ScrollBar;
                    private Color trackBackColor = Color.Empty;
                    /// <summary>
                    /// 轨道背景颜色
                    /// </summary>
                    [Description("轨道背景颜色")]
                    [PropertyOrder(-139)]
                    [SkinProperty(true, false)]
                    public Color TrackBackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinTrackBackColor;
                            }

                            if (this.trackBackColor != Color.Empty)
                            {
                                return this.trackBackColor;
                            }

                            return this.defaultTrackBackColor;
                        }
                        set
                        {
                            if (this.trackBackColor == value)
                                return;

                            this.trackBackColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeTrackBackColor()
                    {
                        return this.trackBackColor != Color.Empty;
                    }
                    private void ResetTrackBackColor()
                    {
                        this.trackBackColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinThumbBackColor = Color.Empty;
                    private readonly Color defaultThumbBackColor = SystemColors.WindowFrame;
                    private Color thumbBackColor = Color.Empty;
                    /// <summary>
                    /// 拇指背景颜色
                    /// </summary>
                    [Description("拇指背景颜色")]
                    [PropertyOrder(-134)]
                    [SkinProperty(true, false)]
                    public Color ThumbBackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinThumbBackColor;
                            }

                            if (this.thumbBackColor != Color.Empty)
                            {
                                return this.thumbBackColor;
                            }

                            return this.defaultThumbBackColor;
                        }
                        set
                        {
                            if (this.thumbBackColor == value)
                                return;

                            this.thumbBackColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeThumbBackColor()
                    {
                        return this.thumbBackColor != Color.Empty;
                    }
                    private void ResetThumbBackColor()
                    {
                        this.thumbBackColor = Color.Empty;
                        this.Invalidate();
                    }

                    #endregion

                }

            }

        }

        #endregion

    }
}
